mirror of
https://github.com/koodiklinikka/koodiklinikka.fi-api.git
synced 2026-02-07 07:49:56 +00:00
read config also from environment variables, merge on top of json file config
This commit is contained in:
@@ -4,4 +4,18 @@ var _ = require('lodash');
|
||||
var config = require('../config.json');
|
||||
var env = process.env.NODE_ENV || 'development';
|
||||
|
||||
module.exports = _.merge({}, config.all, config[env]);
|
||||
// TWITTER_CONSUMER_KEY => twitter.consumerKey
|
||||
function toPath(key) {
|
||||
var parts = key.split('_');
|
||||
|
||||
var namespace = parts[0].toLowerCase();
|
||||
var option = _.camelCase(_.tail(parts).join('_'))
|
||||
|
||||
return option ? [namespace, option].join('.') : namespace;
|
||||
}
|
||||
|
||||
var envVars = _.reduce(process.env, function(memo, value, key) {
|
||||
return _.set(memo, toPath(key), value);
|
||||
}, {});
|
||||
|
||||
module.exports = _.merge({}, config.all, config[env], envVars);
|
||||
|
||||
Reference in New Issue
Block a user