mirror of https://github.com/embarklabs/embark.git
Delay the start of the proxy
This commit is contained in:
parent
7ce92211f9
commit
4c0b4c2410
|
@ -58,8 +58,6 @@ var Blockchain = function(options) {
|
||||||
verbosity: this.blockchainConfig.verbosity
|
verbosity: this.blockchainConfig.verbosity
|
||||||
};
|
};
|
||||||
|
|
||||||
this.setupProxy();
|
|
||||||
|
|
||||||
if (this.blockchainConfig === {} || JSON.stringify(this.blockchainConfig) === '{"enabled":true}') {
|
if (this.blockchainConfig === {} || JSON.stringify(this.blockchainConfig) === '{"enabled":true}') {
|
||||||
this.config.account = {};
|
this.config.account = {};
|
||||||
this.config.account.password = fs.embarkPath("templates/boilerplate/config/development/password");
|
this.config.account.password = fs.embarkPath("templates/boilerplate/config/development/password");
|
||||||
|
@ -80,26 +78,28 @@ var Blockchain = function(options) {
|
||||||
console.error(__(spaceMessage, 'genesisBlock'));
|
console.error(__(spaceMessage, 'genesisBlock'));
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
|
this.initProxy();
|
||||||
this.client = new options.client({config: this.config, env: this.env, isDev: this.isDev});
|
this.client = new options.client({config: this.config, env: this.env, isDev: this.isDev});
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockchain.prototype.setupProxy = function() {
|
Blockchain.prototype.initProxy = function() {
|
||||||
this.config.proxy = true;
|
this.config.proxy = true;
|
||||||
if (this.blockchainConfig.proxy === false) {
|
if (this.blockchainConfig.proxy === false) {
|
||||||
this.config.proxy = false;
|
this.config.proxy = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.config.rpcPort += constants.blockchain.servicePortOnProxy;
|
||||||
|
this.config.wsPort += constants.blockchain.servicePortOnProxy;
|
||||||
|
};
|
||||||
|
|
||||||
|
Blockchain.prototype.setupProxy = function() {
|
||||||
const proxy = require('./proxy');
|
const proxy = require('./proxy');
|
||||||
const Ipc = require('../../core/ipc');
|
const Ipc = require('../../core/ipc');
|
||||||
|
|
||||||
let ipcObject = new Ipc({ipcRole: 'client'});
|
let ipcObject = new Ipc({ipcRole: 'client'});
|
||||||
|
|
||||||
this.rpcProxy = proxy.serve(ipcObject, this.config.rpcHost, this.config.rpcPort, false);
|
this.rpcProxy = proxy.serve(ipcObject, this.config.rpcHost, this.config.rpcPort, false);
|
||||||
this.wsProxy = proxy.serve(ipcObject, this.config.wsHost, this.config.wsPort, true);
|
this.wsProxy = proxy.serve(ipcObject, this.config.wsHost, this.config.wsPort, true);
|
||||||
this.config.rpcPort += constants.blockchain.servicePortOnProxy;
|
|
||||||
this.config.wsPort += constants.blockchain.servicePortOnProxy;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockchain.prototype.shutdownProxy = function() {
|
Blockchain.prototype.shutdownProxy = function() {
|
||||||
|
@ -126,7 +126,6 @@ Blockchain.prototype.run = function() {
|
||||||
console.log(__("Embark Blockchain Using: %s", this.client.name.underline).magenta);
|
console.log(__("Embark Blockchain Using: %s", this.client.name.underline).magenta);
|
||||||
console.log("===============================================================================".magenta);
|
console.log("===============================================================================".magenta);
|
||||||
console.log("===============================================================================".magenta);
|
console.log("===============================================================================".magenta);
|
||||||
|
|
||||||
this.checkPathLength();
|
this.checkPathLength();
|
||||||
let address = '';
|
let address = '';
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
|
@ -150,6 +149,9 @@ Blockchain.prototype.run = function() {
|
||||||
},
|
},
|
||||||
function getMainCommand(next) {
|
function getMainCommand(next) {
|
||||||
self.client.mainCommand(address, function(cmd, args) {
|
self.client.mainCommand(address, function(cmd, args) {
|
||||||
|
if (self.config.proxy) {
|
||||||
|
self.setupProxy();
|
||||||
|
}
|
||||||
next(null, cmd, args);
|
next(null, cmd, args);
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
|
@ -163,7 +165,6 @@ Blockchain.prototype.run = function() {
|
||||||
let full_cmd = cmd + " " + args.join(' ');
|
let full_cmd = cmd + " " + args.join(' ');
|
||||||
console.log(__("running: %s", full_cmd.underline).green);
|
console.log(__("running: %s", full_cmd.underline).green);
|
||||||
self.child = child_process.spawn(cmd, args, {cwd: process.cwd()});
|
self.child = child_process.spawn(cmd, args, {cwd: process.cwd()});
|
||||||
|
|
||||||
self.child.on('error', (err) => {
|
self.child.on('error', (err) => {
|
||||||
err = err.toString();
|
err = err.toString();
|
||||||
console.error('Blockchain error: ', err);
|
console.error('Blockchain error: ', err);
|
||||||
|
|
|
@ -67,7 +67,7 @@ exports.serve = function (ipc, host, port, ws) {
|
||||||
let proxy = httpProxy.createProxyServer({
|
let proxy = httpProxy.createProxyServer({
|
||||||
target: {
|
target: {
|
||||||
host: canonicalHost(host),
|
host: canonicalHost(host),
|
||||||
port: port + constants.blockchain.servicePortOnProxy
|
port: port
|
||||||
},
|
},
|
||||||
ws: ws
|
ws: ws
|
||||||
});
|
});
|
||||||
|
@ -126,7 +126,7 @@ exports.serve = function (ipc, host, port, ws) {
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
const listenPort = port - constants.blockchain.servicePortOnProxy;
|
||||||
server.listen(port, defaultHost);
|
server.listen(listenPort, defaultHost);
|
||||||
return server;
|
return server;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue