用单个"proxyServer"代理websocket.到多个目标 [英] Proxying websockets with single "proxyServer" to multiple targets

查看:289
本文介绍了用单个"proxyServer"代理websocket.到多个目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am developing a nodeJS websocket proxy server. The use case is when a websocket request comes, I will check its credentials, add new headers and then based on its group (from user id) to redirect the websocket connection to its target webscoket server. I found most of the packages (such as node-http-proxy) supports single target. Is there a package supporting multiple targets ?

推荐答案

在node-http-proxy的README部分中,使用自定义服务器逻辑设置独立的代理服务器":

From the README of node-http-proxy section, "Setup a stand-alone proxy server with custom server logic":

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' });
});

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

Therefore, you should be able to add your decision code in the callback function and then make a proxy.web() call with your determined target.

这篇关于用单个"proxyServer"代理websocket.到多个目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆