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

User customized config #17

merged 2 commits into from
Jan 20, 2015

Conversation

andretw
Copy link
Contributor

@andretw andretw commented Jan 19, 2015

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. And the variables will be overridden by config_heroku.json.
Thus, I don't need to set env variables or change any other stuff any more.
I can test my cody-cms on localhost or heroku easily.

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.
@ticup
Copy link
Collaborator

ticup commented Jan 19, 2015

Great, Thanks for the pull request.

Just for homogeneity, I suggest we do it like this and let the environment variables have the biggest importance.

If you agree, could you be so kind to adjust accordingly and resubmit the pull request?

Thanks!

// 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];
});


@jcoppieters
Copy link
Owner

thanks mate !

wou het eigenlijk vragen aan jou, want moet eerst nog 40 examens verbeteren (is wel nodejs, dus dat valt mee, maar toch)

J.

Re-ordered the loading steps.
@andretw
Copy link
Contributor Author

andretw commented Jan 20, 2015

@ticup yes, to use global env is more reasonable. I've re-ordered the loading steps. Thanks for your advice. 😄

@jcoppieters sorry, I don't understand Dutch. 😭

ticup added a commit that referenced this pull request Jan 20, 2015
User customized config (you can now overwrite the default config by a command-line supplied config  (-c config_name))
@ticup ticup merged commit 878a37f into jcoppieters:master Jan 20, 2015
@ticup
Copy link
Collaborator

ticup commented Jan 20, 2015

Awesome @andretw!
Your changes are now in v3.2.5, which is also pushed to npm.
Congratz and thanks for being the first outside contributor ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants