From 85659987d97be7171cef6c06ccdbc0408978642f Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sat, 4 Mar 2017 14:20:28 -0500 Subject: [PATCH] add support for website config file; reflect real web server config in the dashboard --- boilerplate/config/webserver.json | 5 +++++ demo/config/webserver.json | 5 +++++ lib/core/config.js | 12 ++++++++++++ lib/core/engine.js | 6 ++++-- lib/core/services.js | 5 ++++- test_app/config/webserver.json | 5 +++++ 6 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 boilerplate/config/webserver.json create mode 100644 demo/config/webserver.json create mode 100644 test_app/config/webserver.json diff --git a/boilerplate/config/webserver.json b/boilerplate/config/webserver.json new file mode 100644 index 000000000..c28a31138 --- /dev/null +++ b/boilerplate/config/webserver.json @@ -0,0 +1,5 @@ +{ + "enabled": true, + "host": "localhost", + "port": 8000 +} diff --git a/demo/config/webserver.json b/demo/config/webserver.json new file mode 100644 index 000000000..c28a31138 --- /dev/null +++ b/demo/config/webserver.json @@ -0,0 +1,5 @@ +{ + "enabled": true, + "host": "localhost", + "port": 8000 +} diff --git a/lib/core/config.js b/lib/core/config.js index 294b34196..b014281f0 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -9,6 +9,7 @@ var Config = function(options) { this.blockchainConfig = {}; this.contractsConfig = {}; this.pipelineConfig = {}; + this.webServerConfig = {}; this.chainTracker = {}; this.assetFiles = {}; this.contractsFiles = []; @@ -46,6 +47,7 @@ Config.prototype.loadConfigFiles = function(options) { this.loadPipelineConfigFile(); this.loadContractsConfigFile(); + this.loadWebServerConfigFile(); this.loadChainTrackerFile(); this.loadPluginContractFiles(); }; @@ -148,6 +150,16 @@ Config.prototype.loadCommunicationConfigFile = function() { } }; +Config.prototype.loadWebServerConfigFile = function() { + var webServerConfigJSON = fs.readJSONSync(this.configDir + "webserver.json"); + var defaultWebConfig = { + "enabled": true, + "host": "localhost", + "port": 8000 + }; + this.webServerConfig = utils.recursiveMerge(defaultWebConfig, webServerConfigJSON); +}; + Config.prototype.loadEmbarkConfigFile = function() { var contracts = this.embarkConfig.contracts; this.contractsFiles = this.loadFiles(contracts); diff --git a/lib/core/engine.js b/lib/core/engine.js index 2da3e6c15..41b44e881 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -130,11 +130,13 @@ Engine.prototype.fileWatchService = function(options) { }; Engine.prototype.webServerService = function(options) { + var webServerConfig = this.config.webServerConfig; + if (!webServerConfig.enabled) { return; } this.logger.setStatus("Starting Server"); var server = new Server({ logger: this.logger, - host: options.serverHost, - port: options.serverPort + host: options.serverHost || webServerConfig.host, + port: options.serverPor || webServerConfig.port }); server.start(function(){}); }; diff --git a/lib/core/services.js b/lib/core/services.js index 3b49b22bb..af6d2953e 100644 --- a/lib/core/services.js +++ b/lib/core/services.js @@ -3,6 +3,7 @@ var async = require('async'); var http = require('http'); var utils = require('./utils.js'); +// TODO: needs a refactor and be done in a different way var ServicesMonitor = function(options) { this.logger = options.logger; this.interval = options.interval || 5000; @@ -92,8 +93,10 @@ ServicesMonitor.prototype.check = function() { }); }, function checkDevServer(result, callback) { + var host = self.config.webServerConfig.host || self.serverHost; + var port = self.config.webServerConfig.port || self.serverPort; self.logger.trace('checkDevServer'); - var devServer = 'Webserver (http://' + self.serverHost + ':' + self.serverPort + ')'; + var devServer = 'Webserver (http://' + host + ':' + port + ')'; devServer = (self.runWebserver) ? devServer.green : devServer.red; result.push(devServer); callback(null, result); diff --git a/test_app/config/webserver.json b/test_app/config/webserver.json new file mode 100644 index 000000000..40f46625e --- /dev/null +++ b/test_app/config/webserver.json @@ -0,0 +1,5 @@ +{ + "enabled": true, + "host": "localhost", + "port": 8001 +}