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,3 +1,4 @@
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");
@ -5,7 +6,7 @@ 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")
@ -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");