2017-09-18 25 views
0

我正在開發一個nodeJS websocket代理服務器。用例是當websocket請求到來時,我將檢查它的憑據,添加新的標題,然後基於它的組(來自用戶標識)將websocket連接重定向到其目標webscoket服務器。 我發現大部分軟件包(比如node-http-proxy)都支持單個目標。有支持多個目標的包嗎?代理單個「proxyServer」到多個目標的websocket

回答

0

從節點的HTTP代理部分的自述,「設置一個獨立的代理服務器自定義服務器的邏輯」:

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()

+0

它的工作原理。我結束使用: server.on('upgrade',function(req,socket,head)proxy.ws(req,socket,head,{target:'ws://echo.websocket.org',changeOrigin :true,ws:true},function(e){console.log(e)}); }); }); – Conrad