From d1296abf12b2d2f268988b93fa7e422342e48777 Mon Sep 17 00:00:00 2001 From: Mattias Erming Date: Sat, 11 Oct 2014 14:35:28 +0200 Subject: [PATCH] Clean up server options --- src/command-line/start.js | 21 ++++++++++++--------- src/server.js | 9 ++++----- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/command-line/start.js b/src/command-line/start.js index 2c73810b..6a926cc7 100644 --- a/src/command-line/start.js +++ b/src/command-line/start.js @@ -1,14 +1,15 @@ +var _ = require("lodash"); var ClientManager = new require("../clientManager"); var program = require("commander"); var shout = require("../server"); var Helper = require("../helper"); program - .option("-H, --host ", "host") - .option("-p, --port ", "port") - .option("-B, --bind ", "bind") - .option(" --public", "mode") - .option(" --private", "mode") + .option("-H, --host " , "host") + .option("-P, --port " , "port") + .option("-B, --bind " , "bind") + .option(" --public" , "mode") + .option(" --private" , "mode") .command("start") .description("Start the server") .action(function() { @@ -26,9 +27,11 @@ program console.log("Create a new user with 'shout add '."); console.log(""); } else { - var host = program.host || process.env.IP || config.host; - var port = program.port || process.env.PORT || config.port; - var bind = program.bind || process.env.BIND || config.bind; - shout(port, host, mode, bind); + shout({ + host: program.host || config.host, + port: program.port || config.port, + bind: program.bind || config.bind, + public: mode + }); } }); diff --git a/src/server.js b/src/server.js index b2711122..374b0025 100644 --- a/src/server.js +++ b/src/server.js @@ -11,12 +11,9 @@ var config = {}; var sockets = null; var manager = new ClientManager(); -module.exports = function(port, host, isPublic, localIp) { +module.exports = function(options) { config = Helper.getConfig(); - config.port = port; - config.host = host; - config.public = isPublic; - config.bind = localIp; + config = _.extend(config, options); var app = express() .use(index) @@ -25,6 +22,8 @@ module.exports = function(port, host, isPublic, localIp) { var server = null; var https = config.https || {}; var protocol = https.enable ? "https" : "http"; + var port = config.port; + var host = config.host; if (!https.enable){ server = require("http");