Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User customized config #17

Merged
merged 2 commits into from
Jan 20, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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