Skip to content

Commit

Permalink
Merge pull request #17 from andretw/patch-1
Browse files Browse the repository at this point in the history
User customized config (you can now overwrite the default config by a command-line supplied config  (-c config_name))
  • Loading branch information
ticup committed Jan 20, 2015
2 parents a9340b5 + bddfb32 commit 878a37f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions doc/empty/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,21 @@ cody.server.get("/cody/static/*", function (req, res) {
fileserver.serve();
});

// setup the config from config.json + overwrite by environment values
// setup the config. Order of importance: config.json < -c command line config < environment values
// 1. load default config
cody.config = require('./config');
cody.config.controllers = require("./controllers/");

// 2. if -c exists, overwrite customized config values
if(process.argv.indexOf("-c") != -1){
var extraConfigFilePath = process.argv[process.argv.indexOf("-c") + 1];
var obj = JSON.parse(fs.readFileSync(extraConfigFilePath, 'utf8'));
Object.keys(cody.config).forEach(function (name) {
cody.config[name] = obj[name] || cody.config[name];
});
}

// 3. overwrite environment variable values
Object.keys(cody.config).forEach(function (name) {
cody.config[name] = process.env[name] || cody.config[name];
});
Expand All @@ -48,7 +59,6 @@ cody.startWebApp(cody.server, cody.config, function() {
console.log('Listening on port ' + portNr);
});


if (!process.stderr.isTTY) {
process.on('uncaughtException', function (err) {
console.error('Uncaught exception : ' + err.stack);
Expand Down

0 comments on commit 878a37f

Please sign in to comment.