support specifying web server hostname through -b option

This commit is contained in:
Iuri Matias 2016-10-29 21:41:50 -04:00
parent caaf3acde5
commit 60285ea1c0
4 changed files with 18 additions and 6 deletions

View File

@ -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
});
});
};

View File

@ -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) {

View File

@ -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();
};

View File

@ -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) {