Node http proxy with proxytable and websockets

只谈情不闲聊 提交于 2019-11-30 13:46:49

When you use httpProxy.createServer(), it's not necessary to handle the upgrade event because http-proxy handles it automatically. Thus, your server.on('upgrade', ...) never fires because http-proxy is already handling it internally.

The only time you need to do server.on('upgrade') is when you pass middleware functions to httpProxy.createServer or if you've manually created the server with http.createServer().

In other words, websockets should "just work" through the proxy in your configuration.


However, WebSocket support in http-proxy is currently broken on node v0.10.x because of streams2 (the stream APIs in node core were completely rewritten in 0.10). Also, the most recent release of http-proxy (0.10.2) is broken in node v0.8 because of a botched fix for the streams2 issue.

So you have two options:

  1. Wait for http-proxy to rewrite its internals to cope with streams2.
  2. Downgrade to node v0.8.23 and http-proxy 0.10.1. (At least until #1 happens.)

(You can install old versions of npm modules by running npm install http-proxy@0.10.1.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!