使用单个" proxyServer"代理websockets到多个目标

时间:2017-09-18 06:32:52

标签: node.js websocket proxy node-http-proxy

我正在开发一个nodeJS websocket代理服务器。用例是当websocket请求到来时,我将检查其凭据,添加新标头,然后根据其组(来自用户ID)将websocket连接重定向到其目标webscoket服务器。 我发现大多数软件包(例如node-http-proxy)都支持单个目标。是否有支持多个目标的包?

1 个答案:

答案 0 :(得分:0)

在node-http-proxy部分的自述文件中,“使用自定义服务器逻辑设置独立代理服务器”:

var server = http.createServer(function(req, res) {
  // You can define here your custom logic to handle the request
  // and then proxy the request.
  proxy.web(req, res, { target: 'http://127.0.0.1:5060' });
});

因此,您应该可以在回调函数中添加决策代码,然后使用您确定的proxy.web()进行target调用。