Reputation: 115
I have a create-react-app front end that I need to proxy and change origin to my Flask socket-io back end during development to get around CORS. I have already set up http-proxy-middleware which I have done in past projects with success. My setupProxy.js:
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function (app) {
const wsProxy = createProxyMiddleware('/socket.io', {
target: 'ws://localhost:5000/',
changeOrigin: true,
ws: true,
});
app.use(wsProxy);
};
I'm not doing anything special during socket setup:
const ENDPOINT = 'http://localhost:5000/';
const socket = socketIOClient(ENDPOINT);
When I run the dev server it will not proxy my socket io requests. My server reports:
O _internal(113) _log(): 127.0.0.1 - - [04/Jul/2020 22:23:54] "GET /socket.io/?EIO=3&transport=polling&t=NCRjjNJ HTTP/1.1" 400 -
O server(333) handle_request(): http://localhost:3000 is not an accepted origin.
Any thoughts on what I could be doing incorrectly?
Upvotes: 1
Views: 682
Reputation: 67507
Have you done anything to configure cross-origin access in your Flask-SocketIO server? Add cors_allowed_origins='http://localhost:3000'
to your SocketIO()
object and then you should be fine.
Upvotes: 2