Clean up server options

This commit is contained in:
Mattias Erming 2014-10-11 14:35:28 +02:00
parent 9cc793ef9e
commit d1296abf12
2 changed files with 16 additions and 14 deletions

View file

@ -1,14 +1,15 @@
var _ = require("lodash");
var ClientManager = new require("../clientManager"); var ClientManager = new require("../clientManager");
var program = require("commander"); var program = require("commander");
var shout = require("../server"); var shout = require("../server");
var Helper = require("../helper"); var Helper = require("../helper");
program program
.option("-H, --host <ip>", "host") .option("-H, --host <ip>" , "host")
.option("-p, --port <port>", "port") .option("-P, --port <port>" , "port")
.option("-B, --bind <ip>", "bind") .option("-B, --bind <ip>" , "bind")
.option(" --public", "mode") .option(" --public" , "mode")
.option(" --private", "mode") .option(" --private" , "mode")
.command("start") .command("start")
.description("Start the server") .description("Start the server")
.action(function() { .action(function() {
@ -26,9 +27,11 @@ program
console.log("Create a new user with 'shout add <name>'."); console.log("Create a new user with 'shout add <name>'.");
console.log(""); console.log("");
} else { } else {
var host = program.host || process.env.IP || config.host; shout({
var port = program.port || process.env.PORT || config.port; host: program.host || config.host,
var bind = program.bind || process.env.BIND || config.bind; port: program.port || config.port,
shout(port, host, mode, bind); bind: program.bind || config.bind,
public: mode
});
} }
}); });

View file

@ -11,12 +11,9 @@ var config = {};
var sockets = null; var sockets = null;
var manager = new ClientManager(); var manager = new ClientManager();
module.exports = function(port, host, isPublic, localIp) { module.exports = function(options) {
config = Helper.getConfig(); config = Helper.getConfig();
config.port = port; config = _.extend(config, options);
config.host = host;
config.public = isPublic;
config.bind = localIp;
var app = express() var app = express()
.use(index) .use(index)
@ -25,6 +22,8 @@ module.exports = function(port, host, isPublic, localIp) {
var server = null; var server = null;
var https = config.https || {}; var https = config.https || {};
var protocol = https.enable ? "https" : "http"; var protocol = https.enable ? "https" : "http";
var port = config.port;
var host = config.host;
if (!https.enable){ if (!https.enable){
server = require("http"); server = require("http");