Proxying websockets with single “proxyServer” to multiple targets

懵懂的女人 提交于 2019-12-12 04:37:54

问题


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 ?


回答1:


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

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.



来源:https://stackoverflow.com/questions/46272908/proxying-websockets-with-single-proxyserver-to-multiple-targets

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