Skip to content

Commit

Permalink
fix null env bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Contra committed Dec 19, 2015
1 parent 8ed90fa commit b3e05f9
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@ var merge = require('lodash.merge');
var path = require('path');
var env = argv.env || process.env.NODE_ENV;

var envConfigPath, defaultConfigPath, cfgDir,
defaultConfig, envConfig;

// figure out where the config files are at
var cfgDir = process.env.NODE_CONFIG_DIR;
cfgDir = process.env.NODE_CONFIG_DIR;
if (!cfgDir) {
cfgDir = path.resolve(process.cwd, 'config/') + '/';
} else {
cfgDir = path.resolve(cfgDir) + '/';
}


var defaultConfigPath = path.join(cfgDir, 'default');
var envConfigPath = path.join(cfgDir, env);

var defaultConfig, envConfig;
if (env) {
envConfigPath = path.join(cfgDir, env);
}

try {
defaultConfig = require(defaultConfigPath);
Expand All @@ -25,7 +30,11 @@ try {
}

try {
envConfig = require(envConfigPath);
if (envConfigPath) {
envConfig = require(envConfigPath);
} else {
envConfig = {};
}
} catch (err) {
envConfig = {}; // no env specified
}
Expand Down

0 comments on commit b3e05f9

Please sign in to comment.