Open jmattheis opened 4 years ago
This is not a bug, according to README.md:
We do not do any error handling of messages passed between client and proxy, and messages passed between proxy and target, so it is recommended that you listen on errors and handle them.
So you have to listen to the 'error' event and do the handling yourself.
@carl-vbn Thanks for your answer. Could you give me an example on how to do this? I've added such a listener above. Still, my node process crashes/exits after an error occurs, and I'd have to restart my node server to get the proxy in a working state.
I'm sorry I didn't properly look through your code. I ran it myself and got the same problem. From the stack trace it doesn't look like the error is thrown by http-proxy itself, so it might really be a bug. Sorry for overlooking part of your problem, I'll let you know if I find a solution.
proxy.on('proxyReqWs', (proxyReq, req, socket, options, head) => { socket.on('error', (error) => { console.error(error); }); });
☝️ Helped me to solve the same problem
@jmattheis Dude, if its not too late try this out....
const proxyConfig = { target: { host: "localhost", port: 3000, }, ws: true, // Add this... no special wss configuration is required. };
const proxy = httpProxy.createProxyServer(proxyConfig); proxy.listen(5000);
hitting it with this link -> ws://localhost:5000/graphql
Hope this helps, I found it snooping through some issues #1041 (comment)
@stephanrotolante The problem isn't that the proxying doesn't work, it does. But accessing a not websocket path results in a crash of the whole script.
@fromtexas This solution works! Thank you. Still I think this is a bug, a misconfigured server shouldn't result in a application crash.
Got the same error and solved it the way @fromtexas said. I think that should be on the docs.
Having the same issue. Very annoying
After connecting to a path that doesn't exist, the server crashes
Error: