mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-12 06:44:37 +00:00
move pingEndpoint to utils
This commit is contained in:
parent
ba66d763fe
commit
aa02aeb74c
@ -256,45 +256,8 @@ class Blockchain {
|
|||||||
if (!self.contractsConfig || !self.contractsConfig.deployment || !self.contractsConfig.deployment.host) {
|
if (!self.contractsConfig || !self.contractsConfig.deployment || !self.contractsConfig.deployment.host) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
const origin = self.blockchainConfig.wsOrigins.split(',')[0];
|
const {host, port, type, protocol} = self.contractsConfig.deployment;
|
||||||
const options = {
|
utils.pingEndpoint(host, port, type, protocol, self.blockchainConfig.wsOrigins.split(',')[0], next);
|
||||||
protocolVersion: 13,
|
|
||||||
perMessageDeflate: true,
|
|
||||||
origin: origin,
|
|
||||||
host: self.contractsConfig.deployment.host,
|
|
||||||
port: self.contractsConfig.deployment.port
|
|
||||||
};
|
|
||||||
if (self.contractsConfig.deployment.type === 'ws') {
|
|
||||||
options.headers = {
|
|
||||||
'Sec-WebSocket-Version': 13,
|
|
||||||
Connection: 'Upgrade',
|
|
||||||
Upgrade: 'websocket',
|
|
||||||
'Sec-WebSocket-Extensions': 'permessage-deflate; client_max_window_bits',
|
|
||||||
Origin: origin
|
|
||||||
};
|
|
||||||
}
|
|
||||||
let req;
|
|
||||||
// remove trailing api key from infura, ie rinkeby.infura.io/nmY8WtT4QfEwz2S7wTbl
|
|
||||||
if(options.host.indexOf('/') > -1){
|
|
||||||
options.host = options.host.split('/')[0];
|
|
||||||
}
|
|
||||||
if((self.contractsConfig.deployment.protocol || 'http') === 'https'){
|
|
||||||
req = require('https').get(options);
|
|
||||||
}else{
|
|
||||||
req = require('http').get(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
req.on('error', (err) => {
|
|
||||||
next(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
req.on('response', (_response) => {
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
|
|
||||||
req.on('upgrade', (_res, _socket, _head) => {
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
], function (err) {
|
], function (err) {
|
||||||
if (!noLogs && err === NO_NODE_ERROR) {
|
if (!noLogs && err === NO_NODE_ERROR) {
|
||||||
|
@ -73,6 +73,48 @@ function httpsGetJson(url, callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pingEndpoint(host, port, type, protocol, wsOrigins, callback) {
|
||||||
|
const origin = wsOrigins.split(',')[0];
|
||||||
|
const options = {
|
||||||
|
protocolVersion: 13,
|
||||||
|
perMessageDeflate: true,
|
||||||
|
origin: origin,
|
||||||
|
host: host,
|
||||||
|
port: port
|
||||||
|
};
|
||||||
|
if (type === 'ws') {
|
||||||
|
options.headers = {
|
||||||
|
'Sec-WebSocket-Version': 13,
|
||||||
|
Connection: 'Upgrade',
|
||||||
|
Upgrade: 'websocket',
|
||||||
|
'Sec-WebSocket-Extensions': 'permessage-deflate; client_max_window_bits',
|
||||||
|
Origin: origin
|
||||||
|
};
|
||||||
|
}
|
||||||
|
let req;
|
||||||
|
// remove trailing api key from infura, ie rinkeby.infura.io/nmY8WtT4QfEwz2S7wTbl
|
||||||
|
if(options.host.indexOf('/') > -1){
|
||||||
|
options.host = options.host.split('/')[0];
|
||||||
|
}
|
||||||
|
if(protocol === 'https') {
|
||||||
|
req = require('https').get(options);
|
||||||
|
} else {
|
||||||
|
req = require('http').get(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
req.on('error', (err) => {
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
req.on('response', (_response) => {
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
|
||||||
|
req.on('upgrade', (_res, _socket, _head) => {
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function runCmd(cmd, options) {
|
function runCmd(cmd, options) {
|
||||||
const shelljs = require('shelljs');
|
const shelljs = require('shelljs');
|
||||||
let result = shelljs.exec(cmd, options || {silent: true});
|
let result = shelljs.exec(cmd, options || {silent: true});
|
||||||
@ -267,6 +309,7 @@ module.exports = {
|
|||||||
httpGetJson: httpGetJson,
|
httpGetJson: httpGetJson,
|
||||||
httpsGetJson: httpsGetJson,
|
httpsGetJson: httpsGetJson,
|
||||||
hexToNumber: hexToNumber,
|
hexToNumber: hexToNumber,
|
||||||
|
pingEndpoint,
|
||||||
decodeParams: decodeParams,
|
decodeParams: decodeParams,
|
||||||
runCmd: runCmd,
|
runCmd: runCmd,
|
||||||
cd: cd,
|
cd: cd,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user