Open that1guy opened 9 years ago
+1
@that1guy Did you see the example in the readme, that listens on "upgrade"?
did this get resolved? I'm having similar issues. Upgrade didn't catch the /socket.io request and thus was never reached.
I was also having similar issues proxying socket.io connections, which I've now solved! Heres an example that might help: https://github.com/MethodGrab/socketio-proxy-boilerplate.
Facing same issue. As a workaround I removed express.It works fine after that.
I also faced the same issue, I'm using different express middlewares which should also run on websocket connection attempts and removing express was not an option.
I implemented proxying for websockets via manually proxying the messages - I've put together some proof-of-concept code here, happy if it helps anybody: https://gist.github.com/frow/eb0b649bce510587299741d34dc486c5
I ended up wrapping the express instance in http.createServer
.
Looks a bit like this:
import * as http from "http";
const server = http.createServer(app); // where app is the Express app
const httpProxy = require("http-proxy");
const proxy = httpProxy.createProxyServer({ target: "http://localhost:3001", ws: true });
app.use((req, res) => proxy.web(req, res));
server.on("upgrade", (req, socket, head) => {
proxy.ws(req, socket, head);
});
server.listen(port, () => {
console.log("Listening at http://localhost:" + port + "/");
});
I'm trying to run a proxy server on port 8081 that can re-route http traffic and socket.io traffic. I'm using express server because I use passport for authentication.
I can get http-proxy to route all http traffic on 8081 and all websocket traffic directed to 8082, but I cant figure out how to handle both protocols on one port. Ideas?
This first technique just causes client-side xhr requests to hit the server at a rate of about 3 requests per second.
This second method catches the websocket request, but obviously doesn't get upgraded.
I've tried a 3rd method using .ws method but no luck there either.