Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
creating a local.example.js as a sample file to extend configuration …
Browse files Browse the repository at this point in the history
…to local repository without committing these changes and also replacing .extend() with .merge() for local repository changes
  • Loading branch information
lirantal committed May 13, 2015
1 parent aca6a79 commit dce17e9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
22 changes: 17 additions & 5 deletions config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,26 @@ var _ = require('lodash'),
glob = require('glob'),
fs = require('fs');

/**
* Resolve environment configuration by extending each env configuration file,
* and lastly merge/override that with any local repository configuration that exists
* in local.js
*/
var resolvingConfig = function() {
var conf = {};

conf = _.extend(
require('./env/all'),
require('./env/' + process.env.NODE_ENV) || {}
);

return _.merge(conf, (fs.existsSync('./config/env/local.js') && require('./env/local.js')) || {});
};

/**
* Load app configurations
*/
module.exports = _.extend(
require('./env/all'),
require('./env/' + process.env.NODE_ENV),
(fs.existsSync('./config/env/local.js') && require('./env/local.js')) || {}
);
module.exports = resolvingConfig();

/**
* Get files by glob patterns
Expand Down
23 changes: 23 additions & 0 deletions config/env/local.example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

// Rename this file to local.js for having a local configuration variables that
// will not get commited and pushed to remote repositories.
// Use it for your API keys, passwords, etc.

/* For example:
module.exports = {
db: {
uri: 'mongodb://localhost/local-dev',
options: {
user: '',
pass: ''
}
},
facebook: {
clientID: process.env.FACEBOOK_ID || 'APP_ID',
clientSecret: process.env.FACEBOOK_SECRET || 'APP_SECRET',
callbackURL: '/auth/facebook/callback'
}
};
*/
2 changes: 1 addition & 1 deletion gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ module.exports = function(grunt) {
},
copy: {
localConfig: {
src: 'config/env/development.js',
src: 'config/env/local.example.js',
dest: 'config/env/local.js',
filter: function() {
return !fs.existsSync('config/env/local.js');
Expand Down

0 comments on commit dce17e9

Please sign in to comment.