@@ -3,9 +3,11 @@ const http = require('http');
33const constants = require ( '../constants.json' ) ;
44
55let commList = { } ;
6- let transactions = { } ;
6+ let transactions = { } ;
77let receipts = { } ;
88
9+ const { canonicalHost, defaultHost} = require ( '../utils/host' ) ;
10+
911const parseRequest = function ( reqBody ) {
1012 let jsonO ;
1113 try {
@@ -42,7 +44,7 @@ const parseResponse = function(ipc, resBody){
4244 commList [ receipts [ jsonO . id ] ] . blockNumber = jsonO . result . blockNumber ;
4345 commList [ receipts [ jsonO . id ] ] . gasUsed = jsonO . result . gasUsed ;
4446 commList [ receipts [ jsonO . id ] ] . status = jsonO . result . status ;
45-
47+
4648 if ( ipc . connected && ! ipc . connecting ) {
4749 ipc . request ( 'log' , commList [ receipts [ jsonO . id ] ] ) ;
4850 } else {
@@ -61,7 +63,7 @@ const parseResponse = function(ipc, resBody){
6163exports . serve = function ( ipc , host , port , ws ) {
6264 let proxy = httpProxy . createProxyServer ( {
6365 target : {
64- host,
66+ host : canonicalHost ( host ) ,
6567 port : port + constants . blockchain . servicePortOnProxy
6668 } ,
6769 ws : ws
@@ -80,7 +82,7 @@ exports.serve = function(ipc, host, port, ws){
8082 if ( resBody ) {
8183 parseResponse ( ipc , resBody ) ;
8284 }
83- } ) ;
85+ } ) ;
8486 } ) ;
8587
8688 let server = http . createServer ( ( req , res ) => {
@@ -110,16 +112,16 @@ exports.serve = function(ipc, host, port, ws){
110112 parseResponse ( ipc , data . toString ( ) . substr ( data . indexOf ( "{" ) ) ) ;
111113 } ) ;
112114 } ) ;
113-
115+
114116 proxy . on ( 'proxyReqWs' , ( proxyReq , req , socket ) => {
115117 var parser = new WsParser ( 0 , false ) ;
116118 socket . pipe ( parser ) ;
117119 parser . on ( 'frame' , function ( frame ) {
118120 parseRequest ( frame . data ) ;
119121 } ) ;
120-
122+
121123 } ) ;
122124 }
123125
124- server . listen ( port ) ;
126+ server . listen ( port , defaultHost ) ;
125127} ;
0 commit comments