mirror of https://github.com/embarklabs/embark.git
proxy should attempt to wait on target
This commit is contained in:
parent
3846db79f7
commit
b9975668b8
|
@ -1,6 +1,7 @@
|
||||||
const httpProxy = require('http-proxy');
|
const httpProxy = require('http-proxy');
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
const constants = require('../../constants.json');
|
const constants = require('../../constants.json');
|
||||||
|
const utils = require('../../utils/utils');
|
||||||
|
|
||||||
let commList = {};
|
let commList = {};
|
||||||
let transactions = {};
|
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({
|
let proxy = httpProxy.createProxyServer({
|
||||||
target: {
|
target: {
|
||||||
host: canonicalHost(host),
|
host: canonicalHost(host),
|
||||||
|
|
Loading…
Reference in New Issue