Skip to content

Commit

Permalink
Merge pull request #350 from folio-org/STCLI-246
Browse files Browse the repository at this point in the history
STCLI-246 Add a proxy server to overcome issues with cookies SameSite policy.
  • Loading branch information
BogdanDenis committed Jun 18, 2024
2 parents adafbcf + a79d797 commit 5b4700f
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 3.2.0 IN PROGRESS

* Add a proxy server to overcome issues with cookies SameSite policy. Refs STCLI-246.

## [3.1.0](https://github.com/folio-org/stripes-cli/tree/v3.1.0) (2024-03-12)
[Full Changelog](https://github.com/folio-org/stripes-cli/compare/v3.0.0...v3.1.0)

Expand Down
6 changes: 6 additions & 0 deletions doc/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,8 @@ Option | Description | Type | Notes
`--port` | Development server port | number | default: 3000
`--stripesConfig` | Stripes config JSON | string | supports stdin
`--tenant` | Specify a tenant ID | string |
`--startProxy` | Start a local proxy server between the platform and okapi | boolean | default: false
`--proxyPort` | Port number for the proxy server | number | default: 3010

Examples:

Expand All @@ -1146,6 +1148,10 @@ Serve a build previously created with "stripes build":
```
$ stripes serve --existing-build output
```
Serve a platform with a local proxy server that points to a remote okapi server:
```
$ stripes serve --startProxy --proxyPort 3010 --okapi http://some-okapi-server.folio.org
```
Serve an app (in app context) with a mock backend server":
```
$ stripes serve --mirage
Expand Down
12 changes: 12 additions & 0 deletions lib/commands/common-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ module.exports.serverOptions = {
default: 3000,
group: 'Server Options:',
},
startProxy: {
type: 'boolean',
describe: 'Start a proxy server',
default: false,
group: 'Server Options:',
},
proxyPort: {
type: 'number',
describe: 'Proxy server port',
default: 3010,
group: 'Server Options:',
},
host: {
type: 'string',
describe: 'Development server host',
Expand Down
18 changes: 18 additions & 0 deletions lib/commands/serve.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const importLazy = require('import-lazy')(require);
const childProcess = require('child_process');
const path = require('path');

const { contextMiddleware } = importLazy('../cli/context-middleware');
const { stripesConfigMiddleware } = importLazy('../cli/stripes-config-middleware');
Expand All @@ -12,6 +14,15 @@ const server = importLazy('../server');
const serveBuildOptions = Object.assign({}, buildOptions);
delete serveBuildOptions.publicPath;

function replaceArgvOkapiWithProxyURL(argv) {
const proxyURL = `http://localhost:${argv.proxyPort}`;
argv.okapi = proxyURL;

if (argv.stripesConfig?.okapi) {
argv.stripesConfig.okapi.url = proxyURL;
}
}

function serveCommand(argv) {
const context = argv.context;
// Default serve command to development env
Expand Down Expand Up @@ -39,6 +50,13 @@ function serveCommand(argv) {
return;
}

if (argv.startProxy) {
console.info('starting proxy');
childProcess.fork(path.resolve(context.cliRoot, './lib/run-proxy.js'), [argv.okapi, argv.proxyPort]);
// if we're using a proxy server - we need to pass the proxy host as okapi to Stripes platform
replaceArgvOkapiWithProxyURL(argv);
}

const platform = new StripesPlatform(argv.stripesConfig, context, argv);

const webpackOverrides = platform.getWebpackOverrides(context);
Expand Down
1 change: 1 addition & 0 deletions lib/platform/tenant-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const defaultConfig = {
showPerms: false,
hasAllPerms: false,
languages: ['en'],
useSecureTokens: true,
},
modules: {
},
Expand Down
17 changes: 17 additions & 0 deletions lib/run-proxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');

const app = express();

const OKAPI = process.argv[2];
const PORT = process.argv[3];

app.use(
'/',
createProxyMiddleware({
target: OKAPI,
changeOrigin: true,
}),
);

app.listen(PORT);
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"fs-extra": "^11.1.1",
"get-stdin": "^6.0.0",
"global-dirs": "^0.1.1",
"http-proxy-middleware": "^3.0.0",
"import-lazy": "^3.1.0",
"inquirer": "^8.2.0",
"is-installed-globally": "^0.4.0",
Expand Down

0 comments on commit 5b4700f

Please sign in to comment.