Permalink
Browse files

server-node: Support for setting 'hostname' http option

You can now select which hostname to listen on via

1: Command line option:

  $ node osjs run --hostname=::

2: Configuration

  $ node osjs config:set --name=server.http.hostname --value="::"
  $ node osjs build:config
  $ node osjs run
  • Loading branch information...
andersevenrud committed May 22, 2017
1 parent 087e104 commit 3adf1a0b8129d01bc910d82e97e9336ffec0277a
View
@@ -306,6 +306,7 @@ module.exports.run = function(cli, args) {
const settings = require(_path.join(ROOT, 'src/server/node/core/settings.js'));
const opts = {
HOSTNAME: cli.option('hostname'),
DEBUG: cli.option('debug'),
PORT: cli.option('port'),
LOGLEVEL: cli.option('loglevel')
View
@@ -32,6 +32,7 @@
"http": {
"mode": "http",
"connection": "%connection%",
"hostname": null,
"port" : 8000,
"compression": {
"memLevel": 8,
@@ -37,6 +37,7 @@ const _path = require('path');
*/
const ENV = {
HOSTNAME: null,
DEBUG: false,
PORT: null,
LOGLEVEL: -2,
@@ -93,6 +94,10 @@ module.exports.update = function(config) {
ENV.PORT = config.http.port;
}
if ( !ENV.HOSTNAME && config.http.hostname ) {
ENV.HOSTNAME = config.http.hostname;
}
if ( config.overlays ) {
Object.keys(config.overlays).forEach((name) => {
const overlay = config.overlays[name];
@@ -543,13 +543,14 @@ module.exports.init = function init() {
/**
* Runs the HTTP server
*
* @param {Number} port Which port number
* @param {Number} port Which port number
* @param {String} [hostname] Which hostname
*
* @function run
* @memberof core.http
*/
module.exports.run = function run(port) {
httpServer.listen(port);
module.exports.run = function run(port, hostname) {
httpServer.listen(port, hostname);
};
/**
@@ -395,7 +395,7 @@ module.exports.run = function run(port) {
_evhandler.emit('server:run');
_logger.log('INFO', _logger.colored('Starting OS.js server', 'green'));
_logger.log('INFO', _logger.colored(['Running', httpConfig.mode, 'on localhost:' + ENV.PORT].join(' '), 'green'));
_logger.log('INFO', _logger.colored(['Running', httpConfig.mode, 'on', (ENV.HOSTNAME || 'localhost') + ':' + ENV.PORT].join(' '), 'green'));
if ( httpConfig.connection === 'ws' ) {
const wsp = httpConfig.ws.port === 'upgrade' ? ENV.PORT : httpConfig.ws.port;
@@ -409,7 +409,7 @@ module.exports.run = function run(port) {
_logger.log('INFO', _logger.colored('Running in production mode', 'yellow'));
}
const result = _http.run(ENV.PORT);
const result = _http.run(ENV.PORT, ENV.HOSTNAME);
_logger.log('INFO', _logger.colored('Ready...', 'green'));
return result;
@@ -46,6 +46,7 @@ const _minimist = require('minimist');
const argv = _minimist(process.argv.slice(2));
const opts = {
DEBUG: argv.debug,
HOSTNAME: argv.h || argv.hostname,
ROOT: argv.r || argv.root,
PORT: argv.p || argv.port,
LOGLEVEL: argv.l || argv.loglevel,

0 comments on commit 3adf1a0

Please sign in to comment.