From 9b37f807df5dbaa351371a3e3b0f871dff0d6df9 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Fri, 8 Jun 2018 13:44:16 -0400 Subject: [PATCH] Websocket support --- lib/cmds/blockchain/blockchain.js | 4 ++-- lib/core/proxy.js | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/cmds/blockchain/blockchain.js b/lib/cmds/blockchain/blockchain.js index 3bab4daad..ea492cdf7 100644 --- a/lib/cmds/blockchain/blockchain.js +++ b/lib/cmds/blockchain/blockchain.js @@ -82,9 +82,9 @@ Blockchain.prototype.setupProxy = function(){ let ipcObject = new Ipc({ipcRole: 'client'}); proxy.serve(ipcObject, this.config.rpcHost, this.config.rpcPort, false); - // proxy.serve(ipcObject, this.config.wsHost, this.config.wsPort, true); + proxy.serve(ipcObject, this.config.wsHost, this.config.wsPort, true); this.config.rpcPort += 10; - //this.config.wsPort += 10; + this.config.wsPort += 10; } }; diff --git a/lib/core/proxy.js b/lib/core/proxy.js index 4e975d164..8cdacef41 100644 --- a/lib/core/proxy.js +++ b/lib/core/proxy.js @@ -7,9 +7,9 @@ exports.serve = function(ipc, host, port, ws){ let proxy = httpProxy.createProxyServer({ target: { host: host, - port: port + 10, - ws: ws - } + port: port + 10 + }, + ws: ws }); proxy.on('proxyRes', (proxyRes) => { @@ -32,7 +32,7 @@ exports.serve = function(ipc, host, port, ws){ delete commList[jsonO.id]; } } catch(e){ - // + // } }); }); @@ -54,13 +54,16 @@ exports.serve = function(ipc, host, port, ws){ } }); - if(ws){ - proxy.ws(req, res); - } else { + if(!ws){ proxy.web(req, res); } - }); + if(ws){ + server.on('upgrade', function (req, socket, head) { + proxy.ws(req, socket, head); + }); + } + server.listen(port); };