Skip to content

Commit

Permalink
reset Access-Control-Allow-* headers to avoid CORS issues
Browse files Browse the repository at this point in the history
  • Loading branch information
zburke committed Aug 22, 2024
1 parent 776ce14 commit 8a7a069
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function serveCommand(argv) {

if (argv.startProxy) {
console.info('starting proxy');
childProcess.fork(path.resolve(context.cliRoot, './lib/run-proxy.js'), [argv.okapi, argv.proxyPort]);
childProcess.fork(path.resolve(context.cliRoot, './lib/run-proxy.js'), [argv.okapi, argv.proxyPort, argv.port]);
// if we're using a proxy server - we need to pass the proxy host as okapi to Stripes platform
replaceArgvOkapiWithProxyURL(argv);
}
Expand Down
11 changes: 9 additions & 2 deletions lib/run-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ const { createProxyMiddleware } = require('http-proxy-middleware');
const app = express();

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

app.use(
'/',
createProxyMiddleware({
target: OKAPI,
changeOrigin: true,
on: {
proxyRes: (proxyRes) => {
proxyRes.headers['Access-Control-Allow-Origin'] = `http://localhost:${PORT}`;
proxyRes.headers['Access-Control-Allow-Credentials'] = 'true';
},
},
}),
);

app.listen(PORT);
app.listen(PROXY_PORT);

0 comments on commit 8a7a069

Please sign in to comment.