diff --git a/lib/modules/blockchain_process/proxy.js b/lib/modules/blockchain_process/proxy.js index 8779bae75..fc731b4fd 100644 --- a/lib/modules/blockchain_process/proxy.js +++ b/lib/modules/blockchain_process/proxy.js @@ -1,6 +1,7 @@ const httpProxy = require('http-proxy'); const http = require('http'); const constants = require('../../constants.json'); +const utils = require('../../utils/utils'); let commList = {}; let transactions = {}; @@ -63,7 +64,31 @@ const parseResponse = function (ipc, resBody) { } }; -exports.serve = function (ipc, host, port, ws) { +exports.serve = async function (ipc, host, port, ws, origin) { + const _origin = origin ? origin.split(',')[0] : void 0; + const start = Date.now(); + + function awaitTarget() { + return new Promise((resolve, reject) => { + utils.pingEndpoint( + canonicalHost(host), port, ws ? 'ws': false, 'http', _origin, async (err) => { + if (!err || (Date.now() - start > 10000)) { + // if (Date.now() - start > 10000) { + // console.warn('!!! TIMEOUT !!!'); + // } else { + // console.warn('!!! CONNECT !!!'); + // } + return resolve(); + } + // console.warn('!!! WAITING !!!'); + await utils.timer(250).then(awaitTarget).then(resolve); + } + ); + }); + } + + await awaitTarget(); + let proxy = httpProxy.createProxyServer({ target: { host: canonicalHost(host),