From 60285ea1c050c3a75a653d7d49a57f35e4166c3a Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sat, 29 Oct 2016 21:41:50 -0400 Subject: [PATCH] support specifying web server hostname through -b option --- lib/cmd.js | 9 +++++++-- lib/index.js | 7 ++++++- lib/server.js | 5 +++-- lib/services.js | 3 ++- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/cmd.js b/lib/cmd.js index 78173758..f9dac0b7 100644 --- a/lib/cmd.js +++ b/lib/cmd.js @@ -62,13 +62,18 @@ Cmd.prototype.run = function() { var self = this; program .command('run [environment]') - .option('-p, --port [port]', 'port to run the dev webserver') + .option('-p, --port [port]', 'port to run the dev webserver (default: 8000)') + .option('-b, --host [host]', 'host to run the dev webserver (default: localhost)') .description('run dapp (default: development)') .action(function(env, options) { self.Embark.initConfig(env || 'development', { embarkConfig: 'embark.json' }); - self.Embark.run({env: env || 'development', serverPort: options.port}); + self.Embark.run({ + env: env || 'development', + serverPort: options.port, + serverHost: options.host + }); }); }; diff --git a/lib/index.js b/lib/index.js index 1358794d..a6de53f7 100644 --- a/lib/index.js +++ b/lib/index.js @@ -80,6 +80,7 @@ var Embark = { Embark.servicesMonitor = new ServicesMonitor({ logger: Embark.logger, config: Embark.config, + serverHost: options.serverHost, serverPort: options.serverPort }); Embark.servicesMonitor.startMonitor(); @@ -88,7 +89,11 @@ var Embark = { self.buildDeployGenerate.bind(self), function startAssetServer(callback) { Embark.monitor.setStatus("Starting Server"); - var server = new Server({logger: self.logger, port: options.serverPort}); + var server = new Server({ + logger: self.logger, + host: options.serverHost, + port: options.serverPort + }); server.start(callback); }, function watchFilesForChanges(callback) { diff --git a/lib/server.js b/lib/server.js index 4af23bb6..fd32c4c5 100644 --- a/lib/server.js +++ b/lib/server.js @@ -5,6 +5,7 @@ var serveStatic = require('serve-static'); var Server = function(options) { this.dist = options.dist || 'dist/'; this.port = options.port || 8000; + this.hostname = options.host || 'localhost'; this.logger = options.logger; }; @@ -15,8 +16,8 @@ Server.prototype.start = function(callback) { serve(req, res, finalhandler(req, res)); }); - this.logger.info(("listening on port " + this.port).underline.green); - server.listen(this.port) ; + this.logger.info(("webserver available at http://" + this.hostname + ":" + this.port).underline.green); + server.listen(this.port, this.hostname) ; callback(); }; diff --git a/lib/services.js b/lib/services.js index 5e4f2f50..2fbec303 100644 --- a/lib/services.js +++ b/lib/services.js @@ -6,6 +6,7 @@ var ServicesMonitor = function(options) { this.logger = options.logger; this.interval = options.interval || 5000; this.config = options.config; + this.serverHost = options.serverHost || 'localhost'; this.serverPort = options.serverPort || 8000; }; @@ -64,7 +65,7 @@ ServicesMonitor.prototype.check = function() { }, function checkDevServer(result, callback) { self.logger.trace('checkDevServer'); - result.push(('dev server (http://localhost:' + self.serverPort + ')').green); + result.push(('dev server (http://' + self.serverHost + ':' + self.serverPort + ')').green); callback(null, result); } ], function(err, result) {