-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebSocket proxy fails if HMR is running on same port #6994
Comments
Thank you. Had the exact same issue, your solution worked perfectly. |
+1 here also. I'm on |
Thank you. Your solution worked for me. |
Thank you so much! I was getting something like below (in case others run into this) on the server side (Scala/Java).
|
AFAIK, this is still an issue. Either a documentation change should be made to inform users of this, or the bug should be fixed. |
This issue is still exist in the latest version. |
This is the relevant code for the case of parcel/packages/reporters/dev-server/src/ServerReporter.js Lines 46 to 55 in 2facd5d
The HTTP server creation including proxyrc is here (the parcel/packages/reporters/dev-server/src/Server.js Lines 465 to 497 in 2facd5d
|
I think the issue is that the HMR server uses ws to create a new WebSocket server with the
This basically ensures that The solution here is to tell the HMR this.wss = new WebSocket.Server({noServer: true}); and then the server's upgrade event would need to be handled manually as shown in this ws usage example: server.on('upgrade', function upgrade(req, socket, head) {
let {pathname} = url.parse(req.originalUrl || req.url);
if (pathname != null && pathname.startsWith(HMR_ENDPOINT)) {
this.wss.handleUpgrade(req, socket, head, function done(ws) {
this.wss.emit('connection', ws, req);
});
}
// else, we simply do nothing and hope the request got proxied
}); |
Anyway, hope this is an easy fix. If you want, I can try my hand at a PR for this. |
PR is still open |
🐛 bug report
When running
parcel serve
where the--port
is the same as the--hmr-port
(the default behavior AFAIK), the WebSocket proxy (i.e..proxyrc
) no longer functions properly.🎛 Configuration
Running this command exhibits the bug:
🤔 Expected Behavior
WebSocket proxy should work. When the browser connects to
ws://localhost:1234/ws
, it should be proxied tolocalhost:1235/ws
using http-proxy-middleware😯 Current Behavior
When the browser establishes the WebSocket connection to
ws://localhost:1234/ws
, parcel indicates that the web browser immediately disconnects:On the WebSocket server running in Go on port 1235, I get an error that seems to indicate that the socket is closed:
On the browser (Firefox), I get a message like this:
which occurs on the line where I create the
new WebSocket(...)
.💁 Possible Solution
Everything runs fine without
parcel
. If Iparcel build
and bypass the parcel server and HMR server, it works.Running Parcel with a different HMR port also seems to work (note that HMR port is set to 1236):
... and in this case, it all works splendidly.
This seems to indicate that
parcel serve
does not properly handle WebSocket proxying with http-proxy-middleware when the HMR server is running on the same port as the normal parcel HTTP server.🔦 Context
I'm just trying to run
parcel serve [entry_point]
and have it work (ideally without a separate HMR port).💻 Code Sample
I can provide a sample upon request, but it will take time.
🌍 Your Environment
The text was updated successfully, but these errors were encountered: