Permalink
Browse files

Fix defaults loading.

  • Loading branch information...
1 parent 7f82900 commit b5b4ac9134a6fc8596d37a1e55f410446c8fd056 @cliffano committed Mar 24, 2013
Showing with 6 additions and 12 deletions.
  1. +6 −12 lib/config.js
View
@@ -3,15 +3,6 @@ var fs = require('fs'),
p = require('path'),
cache;
-function _load(file) {
- if (fs.existsSync(file)) {
- console.log('Loading configuration file %s', file);
- nconf.file({ file: file });
- } else {
- console.warn('Ignoring configuration file %s, does not exist', file);
- }
-}
-
function config(opts) {
if (!cache) {
@@ -20,10 +11,13 @@ function config(opts) {
console.log('Loading configuration for %s environment', env || 'local');
nconf.env();
- var env = nconf.get('APP_ENV');
+ var env = nconf.get('APP_ENV'),
+ defaultsFile = p.join(opts.configDir, 'defaults.json');
- _load(p.join(opts.configDir, env + '.json'));
- _load(p.join(opts.configDir, 'defaults.json'));
+ nconf.file(p.join(opts.configDir, env + '.json'));
+ if (fs.existsSync(defaultsFile)) {
+ nconf.defaults(JSON.parse(fs.readFileSync(defaultsFile)));
+ }
cache = nconf;
}

0 comments on commit b5b4ac9

Please sign in to comment.