Skip to content

Instantly share code, notes, and snippets.

@alexeyraspopov
Last active May 5, 2020 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexeyraspopov/0566fe70b2c51f37c21e1fdc50aaae55 to your computer and use it in GitHub Desktop.
Save alexeyraspopov/0566fe70b2c51f37c21e1fdc50aaae55 to your computer and use it in GitHub Desktop.
Basic proxy setup for create-react-app to work with remote backend
let proxy = require('http-proxy-middleware');
module.exports = app => {
let backend = proxy({
target: process.env.DATAROBOT_ENDPOINT,
changeOrigin: true,
});
let socket = proxy('/socket.io-queue', {
target: process.env.DATAROBOT_ENDPOINT,
changeOrigin: true,
ws: true,
});
app.use(socket);
app.use((req, res, next) => {
if (req.path.startsWith(process.env.PUBLIC_URL)) {
next();
} else {
backend(req, res, next);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment