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

Add NODE_CONFIG_RUNTIME process.env variable to completely overwrite all config data #611

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 24 additions & 6 deletions lib/config.js
Expand Up @@ -16,7 +16,7 @@ var deferConfig = require('../defer').deferConfig,
var DEFAULT_CLONE_DEPTH = 20,
NODE_CONFIG, CONFIG_DIR, RUNTIME_JSON_FILENAME, NODE_ENV, APP_INSTANCE,
HOST, HOSTNAME, ALLOW_CONFIG_MUTATIONS, CONFIG_SKIP_GITCRYPT,
NODE_CONFIG_PARSER,
NODE_CONFIG_PARSER, NODE_CONFIG_RUNTIME,
env = {},
privateUtil = {},
deprecationWarnings = {},
Expand Down Expand Up @@ -508,11 +508,6 @@ util.getConfigSources = function() {
* @return config {Object} The configuration object
*/
util.loadFileConfigs = function(configDir) {

// Initialize
var t = this,
config = {};

// Initialize parameters from command line, environment, or default
NODE_ENV = util.initParam('NODE_ENV', 'development');

Expand All @@ -522,6 +517,29 @@ util.loadFileConfigs = function(configDir) {
// Split files name, for loading multiple files.
NODE_ENV = NODE_ENV.split(',');

// Completely Override configurations from the $NODE_CONFIG_RUNTIME environment variable
if (!configDir) {
NODE_CONFIG_RUNTIME = process.env.NODE_CONFIG_RUNTIME || undefined;
if (NODE_CONFIG_RUNTIME) {
try {
NODE_CONFIG_RUNTIME = JSON.parse(NODE_CONFIG_RUNTIME);
} catch(e) {
NODE_CONFIG_RUNTIME = undefined;
console.error('The $NODE_CONFIG_RUNTIME environment variable is malformed JSON');
throw new Error('Wrong NODE_CONFIG_RUNTIME');
}
configSources.push({
name: "$NODE_CONFIG_RUNTIME",
parsed: NODE_CONFIG_RUNTIME,
});
}
return NODE_CONFIG_RUNTIME;
}

// Initialize
var t = this,
config = {};

CONFIG_DIR = configDir || util.initParam('NODE_CONFIG_DIR', Path.join( process.cwd(), 'config') );
if (CONFIG_DIR.indexOf('.') === 0) {
CONFIG_DIR = Path.join(process.cwd() , CONFIG_DIR);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -44,6 +44,6 @@
"node": ">= 6.0.0"
},
"scripts": {
"test": "./node_modules/vows/bin/vows test/*.js --spec"
"test": "vows test/*.js --spec"
}
}