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';
} catch (e) {
webServerConfig.certOptions = {};
webServerConfig.protocol = 'http';
}
}

View File

@ -62,11 +62,11 @@ class Authenticator {
let self = this;
this.events.once('outputDone', () => {
const {port, host, enabled} = this.embark.config.webServerConfig;
const {protocol, port, host, enabled} = this.embark.config.webServerConfig;
if (enabled) {
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.proxyIpc = null;
this.isStandalone = userConfig.isStandalone;
this.certOptions = userConfig.certOptions;
let defaultWsApi = clientClass.DEFAULTS.WS_API;
@ -150,10 +151,10 @@ Blockchain.prototype.setupProxy = async function () {
let wsProxy;
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 () {
@ -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') {
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.onExitCallback = onExitCallback;
userConfig.logger = logger;
userConfig.certOptions = certOptions;
return new Blockchain(userConfig, clientClass);
};

View File

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

View File

@ -37,7 +37,8 @@ class BlockchainProcessLauncher {
client: this.client,
env: this.env,
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;
};
exports.serve = async (ipc, host, port, ws, origin) => {
exports.serve = async (ipc, host, port, ws, origin, certOptions={}) => {
const commList = {};
const receipts = {};
const transactions = {};
@ -123,6 +123,7 @@ exports.serve = async (ipc, host, port, ws, origin) => {
logLevel: 'warn',
target: `http://${canonicalHost(host)}:${port}`,
ws: ws,
ssl: certOptions,
onError(err, _req, _res) {
console.error(

View File

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