Last active
May 5, 2020 03:43
-
-
Save alexeyraspopov/0566fe70b2c51f37c21e1fdc50aaae55 to your computer and use it in GitHub Desktop.
Basic proxy setup for create-react-app to work with remote backend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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