You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
express.use(path, proxy()) ignores path for websockets #204
@roccomuso You don't need the first occurrence of "context" (passed to express.use) though do you?
I would have thought it would work the same (with or without passing context to express.use), but for some reason, when I pass the context in both ways, and I restart the server, reconnection in the browser fails with WebSocket connection to 'ws://localhost:3000/api/socket.io/?EIO=3&transport=websocket' failed: Connection closed before receiving a handshake responseeven after I refresh the page. If I only pass the context to proxy then I get those errors only until I refresh the page. My head hurts. No idea what's going on.
I was using this code which was working fine when the socket had a successful connection but was throwing an error when the WS_URI was returning an error (404, 500 ...)
I just updated my code with this code and it worked. The second route in the proxy method doesn't seem to be required though. I didn't see my route was not handled by express...
I found my issue. I was using socket.io, which is very particular about how you initialize it. In the target of the proxy, in index.html, I was starting socket.io with:
Is there any workaround for this in current version? I'm trying to proxy WS to my server in create-react-app without breaking reloader that listens on different path.
Activity
chimurai commentedon Sep 27, 2017
Thanks for reporting this @ftes .
I'll have to investigate this.
roccomuso commentedon Sep 27, 2017
I'm having the same issue..
I kinda fixed it passing the "context" twice:
@ftes give it a try.
mattbrunetti commentedon Nov 6, 2017
Slightly off topic:
@roccomuso You don't need the first occurrence of "context" (passed to
express.use) though do you?I would have thought it would work the same (with or without passing context to
express.use), but for some reason, when I pass the context in both ways, and I restart the server, reconnection in the browser fails withWebSocket connection to 'ws://localhost:3000/api/socket.io/?EIO=3&transport=websocket' failed: Connection closed before receiving a handshake responseeven after I refresh the page. If I only pass the context toproxythen I get those errors only until I refresh the page. My head hurts. No idea what's going on.janneh commentedon Nov 24, 2017
I'm experiencing a similar issue.
Where:
Gives:
[HPM] Proxy created: / -> http://www.example.comAnd
Gives:
[HPM] Proxy created: /example -> http://www.example.comJust wanted to put it here since the README example describes it as the first one...
DonovanCharpin commentedon Oct 12, 2018
Oh my god, thanks @roccomuso!
I was using this code which was working fine when the socket had a successful connection but was throwing an error when the WS_URI was returning an error (404, 500 ...)
I just updated my code with this code and it worked. The second route in the proxy method doesn't seem to be required though. I didn't see my route was not handled by express...
kdemarest commentedon May 10, 2019
I have the same issue., BUT http-proxy-middleware WORKS when I proxy traffic from "/".
In the broken case, HTTP traffic routes through the proxy, but the proxy fails to upgrade to websockets.
Here is my use() statement. it appears before all other use() statements.:
And, just in case, right after the server.listen() I have put:
The error I am seeing is:
And a later use() statement reports that it is seeing the following:
When I change my code to read as follows, it WORKS just fine:
kdemarest commentedon May 10, 2019
I found my issue. I was using socket.io, which is very particular about how you initialize it. In the target of the proxy, in index.html, I was starting socket.io with:
when I should have been starting it with:
and the server-side companion code to this is
In my proxy, the code is quite simple:
Hope this helps somebody with a similar problem...
rafalp commentedon Apr 26, 2020
Is there any workaround for this in current version? I'm trying to proxy WS to my server in create-react-app without breaking reloader that listens on different path.
rafalp commentedon May 26, 2020
I've changed this:
to this:
...and its working now :)
make websocket upgrade event work
John-Wickedsick commentedon May 14, 2025
When I try this:
I get an error that createProxyMiddleware only expects one argument
So this doesnt work for me
How can I fix this with the new version?
John-Wickedsick commentedon May 14, 2025
Here is my solution: