Skip to content

Instantly share code, notes, and snippets.

@hanford
Created January 13, 2022 19:41
Show Gist options
  • Save hanford/483d2b3a4ecfc977d335dc5ab7dd73fb to your computer and use it in GitHub Desktop.
Save hanford/483d2b3a4ecfc977d335dc5ab7dd73fb to your computer and use it in GitHub Desktop.
// This proxy is only used for e2e
const proxy = require('express-http-proxy');
const express = require('express');
// const { parse } = require('url');
// const dev = process.env.NODE_ENV !== 'production';
// const handle = app.getRequestHandler();
const port = parseInt(process.env.PORT || 5900, 10);
// const apiHost = process.env.API_HOST ? process.env.API_HOST : 'localhost';
// const apiPort = parseInt(process.env.API_PORT || 5100, 10);
// const NODE_MAJOR_VERSION = process.versions.node.split('.')[0];
// if (NODE_MAJOR_VERSION < 14) {
// throw new Error('Dazzle Requires Node 14 (or higher) ⚠️');
// }
const app = express();
app.post('/playground', proxy(`http://localhost:5005/playground`));
app.post('/playground/*', proxy(`http://localhost:5005/playground/*`));
app.get(
'/*',
proxy(`http://localhost:5000/*`, {
proxyReqOptDecorator(proxyReqOpts) {
proxyReqOpts.headers['origin'] = 'http://localhost:5000';
proxyReqOpts.headers['referer'] = 'http://localhost:5000';
delete proxyReqOpts.headers['sec-fetch-site'];
delete proxyReqOpts.headers['sec-fetch-mode'];
console.log({ proxyReqOpts });
return proxyReqOpts;
},
userResHeaderDecorator(headers, _, userRes) {
delete headers['content-security-policy'];
userRes.removeHeader('content-security-policy');
return headers;
},
}),
);
app.listen(port, err => {
if (err) {
throw err;
}
// eslint-disable-next-line no-console
console.log(`Listening at http://dazzle:${port}/`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment