Adds reverse proxy for geth

This commit is contained in:
Praveen Gupta 2018-12-04 19:11:49 +05:30 committed by Iuri Matias
parent dffb3b3bb0
commit 26d66f6e09
7 changed files with 15 additions and 8 deletions

View File

@ -483,6 +483,7 @@ Config.prototype.loadWebServerConfigFile = function() {
}; };
webServerConfig.protocol = 'https'; webServerConfig.protocol = 'https';
} catch (e) { } catch (e) {
webServerConfig.certOptions = {};
webServerConfig.protocol = 'http'; webServerConfig.protocol = 'http';
} }
} }

View File

@ -62,11 +62,11 @@ class Authenticator {
let self = this; let self = this;
this.events.once('outputDone', () => { this.events.once('outputDone', () => {
const {port, host, enabled} = this.embark.config.webServerConfig; const {protocol, port, host, enabled} = this.embark.config.webServerConfig;
if (enabled) { if (enabled) {
this.logger.info(__('Access the web backend with the following url: %s', this.logger.info(__('Access the web backend with the following url: %s',
(`http://${host}:${port}/embark?token=${this.authToken}`.underline))); (`${protocol}://${host}:${port}/embark?token=${this.authToken}`.underline)));
} }
}); });

View File

@ -27,6 +27,7 @@ var Blockchain = function(userConfig, clientClass) {
this.events = userConfig.events; this.events = userConfig.events;
this.proxyIpc = null; this.proxyIpc = null;
this.isStandalone = userConfig.isStandalone; this.isStandalone = userConfig.isStandalone;
this.certOptions = userConfig.certOptions;
let defaultWsApi = clientClass.DEFAULTS.WS_API; let defaultWsApi = clientClass.DEFAULTS.WS_API;
@ -150,10 +151,10 @@ Blockchain.prototype.setupProxy = async function () {
let wsProxy; let wsProxy;
if (this.config.wsRPC) { if (this.config.wsRPC) {
wsProxy = proxy.serve(this.proxyIpc, this.config.wsHost, this.config.wsPort, true, this.config.wsOrigins); wsProxy = proxy.serve(this.proxyIpc, this.config.wsHost, this.config.wsPort, true, this.config.wsOrigins, this.certOptions);
} }
[this.rpcProxy, this.wsProxy] = await Promise.all([proxy.serve(this.proxyIpc, this.config.rpcHost, this.config.rpcPort, false), wsProxy]); [this.rpcProxy, this.wsProxy] = await Promise.all([proxy.serve(this.proxyIpc, this.config.rpcHost, this.config.rpcPort, false, undefined, this.certOptions), wsProxy]);
}; };
Blockchain.prototype.shutdownProxy = function () { Blockchain.prototype.shutdownProxy = function () {
@ -446,7 +447,7 @@ Blockchain.prototype.initChainAndGetAddress = function (callback) {
}); });
}; };
var BlockchainClient = function(userConfig, clientName, env, onReadyCallback, onExitCallback, logger, _events, _isStandalone) { var BlockchainClient = function(userConfig, clientName, env, certOptions, onReadyCallback, onExitCallback, logger, _events, _isStandalone) {
if ((userConfig === {} || JSON.stringify(userConfig) === '{"enabled":true}') && env !== 'development') { if ((userConfig === {} || JSON.stringify(userConfig) === '{"enabled":true}') && env !== 'development') {
logger.info("===> " + __("warning: running default config on a non-development environment")); logger.info("===> " + __("warning: running default config on a non-development environment"));
} }
@ -473,6 +474,7 @@ var BlockchainClient = function(userConfig, clientName, env, onReadyCallback, on
userConfig.onReadyCallback = onReadyCallback; userConfig.onReadyCallback = onReadyCallback;
userConfig.onExitCallback = onExitCallback; userConfig.onExitCallback = onExitCallback;
userConfig.logger = logger; userConfig.logger = logger;
userConfig.certOptions = certOptions;
return new Blockchain(userConfig, clientClass); return new Blockchain(userConfig, clientClass);
}; };

View File

@ -12,6 +12,7 @@ class BlockchainProcess extends ProcessWrapper {
this.client = options.client; this.client = options.client;
this.env = options.env; this.env = options.env;
this.isDev = options.isDev; this.isDev = options.isDev;
this.certOptions = options.certOptions;
i18n.setOrDetectLocale(options.locale); i18n.setOrDetectLocale(options.locale);
@ -20,6 +21,7 @@ class BlockchainProcess extends ProcessWrapper {
this.blockchainConfig, this.blockchainConfig,
this.client, this.client,
this.env, this.env,
this.certOptions,
this.blockchainReady.bind(this), this.blockchainReady.bind(this),
this.blockchainExit.bind(this), this.blockchainExit.bind(this),
console console

View File

@ -37,7 +37,8 @@ class BlockchainProcessLauncher {
client: this.client, client: this.client,
env: this.env, env: this.env,
isDev: this.isDev, isDev: this.isDev,
locale: this.locale locale: this.locale,
certOptions: this.embark.config.webServerConfig.certOptions
} }
}); });

View File

@ -36,7 +36,7 @@ const parseJsonMaybe = (string) => {
return object; return object;
}; };
exports.serve = async (ipc, host, port, ws, origin) => { exports.serve = async (ipc, host, port, ws, origin, certOptions={}) => {
const commList = {}; const commList = {};
const receipts = {}; const receipts = {};
const transactions = {}; const transactions = {};
@ -123,6 +123,7 @@ exports.serve = async (ipc, host, port, ws, origin) => {
logLevel: 'warn', logLevel: 'warn',
target: `http://${canonicalHost(host)}:${port}`, target: `http://${canonicalHost(host)}:${port}`,
ws: ws, ws: ws,
ssl: certOptions,
onError(err, _req, _res) { onError(err, _req, _res) {
console.error( console.error(

View File

@ -86,7 +86,7 @@ class Simulator {
if(useProxy){ if(useProxy){
let ipcObject = new Ipc({ipcRole: 'client'}); let ipcObject = new Ipc({ipcRole: 'client'});
proxy.serve(ipcObject, host, port, false); proxy.serve(ipcObject, host, port, false, undefined);
} }
} }
} }