Skip to content

Commit

Permalink
Added command line option to set config filename
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisn committed Dec 12, 2014
1 parent 51c162c commit 8257308
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
15 changes: 14 additions & 1 deletion bin/server
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

"use strict";

var app = require('../lib/app');
var version = require('../package.json').version;

var http = require('http');
Expand All @@ -23,6 +22,11 @@ var argv = yargs
alias: "p",
description: "<number> HTTP server port (default: " + DEFAULT_PORT + ")",
requiresArg: true
},
"config-file": { // yargs doesn't allow us to have an option named 'config'.
alias: "c",
description: "<filename> Config file name",
requiresArg: true
}
})
.strict()
Expand All @@ -34,6 +38,15 @@ var argv = yargs
})
.argv;

var configFilename = require('../lib/config-filename');

if (argv["config-file"]) {
configFilename.configFilename = argv["config-file"];
}

// Start the server
var app = require('../lib/app');

app.set('port', argv.port || process.env.PORT || DEFAULT_PORT);

// Start the server
Expand Down
18 changes: 14 additions & 4 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
"use strict";

if(process.env.NODE_ENV === 'test') {
module.exports = require('./config.test');
} else {
module.exports = require('./config.local');
var configFilename = require('./lib/config-filename');

var filename;

if (configFilename.configFilename) {
filename = configFilename.configFilename;
}
else if (process.env.NODE_ENV === 'test') {
filename = './config.test';
}
else {
filename = './config.local';
}

module.exports = require(filename);
5 changes: 5 additions & 0 deletions lib/config-filename.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

module.exports = {
configFilename: ''
};

0 comments on commit 8257308

Please sign in to comment.