From dfaaa58ce016e7c9767f6393c430ac9058677f88 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Sun, 15 Jul 2018 23:49:24 -0500 Subject: [PATCH] propagate `embark run` cli webserver flags to config and service --- lib/core/config.js | 11 +++++++++-- lib/core/engine.js | 7 ++++--- lib/index.js | 7 ++++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/core/config.js b/lib/core/config.js index c2f21d550..ac7debe56 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -12,7 +12,7 @@ var Config = function(options) { this.blockchainConfig = {}; this.contractsConfig = {}; this.pipelineConfig = {}; - this.webServerConfig = {}; + this.webServerConfig = options.webServerConfig; this.chainTracker = {}; this.assetFiles = {}; this.contractsFiles = []; @@ -314,7 +314,14 @@ Config.prototype.loadWebServerConfigFile = function() { let configFilePath = this._getFileOrOject(this.configDir, 'webserver', 'webserver'); - this.webServerConfig = this._mergeConfig(configFilePath, configObject, false); + let webServerConfig = this._mergeConfig(configFilePath, configObject, false); + + if (this.webServerConfig) { + // cli falgs to `embark run` should override configFile and defaults (configObject) + this.webServerConfig = utils.recursiveMerge(webServerConfig, this.webServerConfig); + } else { + this.webServerConfig = webServerConfig; + } }; Config.prototype.loadEmbarkConfigFile = function() { diff --git a/lib/core/engine.js b/lib/core/engine.js index 86c970e37..844efd469 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -16,6 +16,7 @@ class Engine { this.events = options.events; this.context = options.context; this.useDashboard = options.useDashboard; + this.webServerConfig = options.webServerConfig; } init(_options) { @@ -26,7 +27,7 @@ class Engine { let options = _options || {}; this.events = options.events || this.events || new Events(); this.logger = options.logger || new Logger({logLevel: options.logLevel || this.logLevel || 'debug', events: this.events, logFile: this.logFile}); - this.config = new Config({env: this.env, logger: this.logger, events: this.events, context: this.context}); + this.config = new Config({env: this.env, logger: this.logger, events: this.events, context: this.context, webServerConfig: this.webServerConfig}); this.config.loadConfigFiles({embarkConfig: this.embarkConfig, interceptLogs: this.interceptLogs}); this.plugins = this.config.plugins; this.isDev = this.config && this.config.blockchainConfig && (this.config.blockchainConfig.isDev || this.config.blockchainConfig.default); @@ -248,8 +249,8 @@ class Engine { this.watch.start(); } - webServerService() { - this.registerModule('webserver'); + webServerService(_options) { + this.registerModule('webserver', _options); } storageService(_options) { diff --git a/lib/index.js b/lib/index.js index 9dfe3605d..1f604690b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -75,7 +75,12 @@ class Embark { logFile: options.logFile, logLevel: options.logLevel, context: self.context, - useDashboard: options.useDashboard + useDashboard: options.useDashboard, + webServerConfig: { + enabled: options.runWebserver, + host: options.serverHost, + port: options.serverPort + } }); engine.init();