Websocket support

This commit is contained in:
Richard Ramos 2018-06-08 13:44:16 -04:00
parent 586e7c7bbc
commit 9b37f807df
2 changed files with 13 additions and 10 deletions

View File

@ -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;
}
};

View File

@ -7,9 +7,9 @@ exports.serve = function(ipc, host, port, ws){
let proxy = httpProxy.createProxyServer({
target: {
host: host,
port: port + 10,
port: port + 10
},
ws: ws
}
});
proxy.on('proxyRes', (proxyRes) => {
@ -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);
};