From c7f149be449a40d6a40cc93f26fc2a8f9c4d7c1e Mon Sep 17 00:00:00 2001 From: Andre Lee Date: Mon, 19 Jan 2015 12:57:50 +0800 Subject: [PATCH 1/2] User customized config I'm using this on Heroku. I just need to write a config_heroku.json and write "web: node index.js -c config_heroku.json" in Procfile. Thus, I don't need to set env variables or any other stuff and I can test my cody cms on localhost easily. --- doc/empty/index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/empty/index.js b/doc/empty/index.js index 3e93be8..3ad2048 100644 --- a/doc/empty/index.js +++ b/doc/empty/index.js @@ -48,6 +48,14 @@ cody.startWebApp(cody.server, cody.config, function() { console.log('Listening on port ' + portNr); }); +// if -c exists, use the customized config +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]; + }); +} if (!process.stderr.isTTY) { process.on('uncaughtException', function (err) { From bddfb320f0936476cb8a194533ce926f30234b72 Mon Sep 17 00:00:00 2001 From: Andre Lee Date: Tue, 20 Jan 2015 10:22:56 +0800 Subject: [PATCH 2/2] Update index.js Re-ordered the loading steps. --- doc/empty/index.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/doc/empty/index.js b/doc/empty/index.js index 3ad2048..d054dbc 100644 --- a/doc/empty/index.js +++ b/doc/empty/index.js @@ -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]; }); @@ -48,15 +59,6 @@ cody.startWebApp(cody.server, cody.config, function() { console.log('Listening on port ' + portNr); }); -// if -c exists, use the customized config -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]; - }); -} - if (!process.stderr.isTTY) { process.on('uncaughtException', function (err) { console.error('Uncaught exception : ' + err.stack);