Skip to content

Commit

Permalink
Dynamic configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
marob committed Mar 16, 2015
1 parent 0baf709 commit abc1860
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ If you checked out this project from github, you can find a configuration file e

+ Please refer to node-apn's [documentation](https://github.com/argon/node-apn) to see all the available parameters and find how to convert your certificates into the expected format.

#### Dynamic configuration

You can use the "process.env.MY_ENV_VAR" syntax in the config.json file. It will automatically be replaced by the value of the corresponding environment variable.

### 4 - Start server

Expand Down
5 changes: 0 additions & 5 deletions bin/pushserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ _.forEach(program.override, function(valueParam){
var key = array[0];
var value = array[1];

var env = /^process\.env\.(.+)$/.exec(value);
if(env) {
value = process.env[env[1]];
}

var configElement = overrideValues;
var keys = key.split('.');
for(var i = 0 ; i < keys.length - 1 ; i++) {
Expand Down
12 changes: 11 additions & 1 deletion lib/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ var _ = require('lodash');
var config;

var initialize = _.once(function (configFilePath, overrides) {
return config = _.merge({}, require(configFilePath), overrides);
config = _.merge({}, require(configFilePath), overrides);

// Replace any "process.env.*" by its corresponding value
_.forOwn(config, function(value, key){
var env = /^process\.env\.(.+)$/.exec(value);
if(env) {
config[key] = process.env[env[1]];
}
});

return config;
});

var get = function (key) {
Expand Down

0 comments on commit abc1860

Please sign in to comment.