Permalink
Browse files

Rework configuration to allow defaults to be specified

  • Loading branch information...
1 parent ca1c6d8 commit 84838847437ad78e589beb5923615feccbaab89d @saintedlama saintedlama committed Feb 2, 2013
@@ -0,0 +1,7 @@
+module.exports = {
+ address : '127.0.0.1',
+
+ db : {
+ url : 'mongodb://localhost/database'
+ }
+};
@@ -1,8 +1,3 @@
module.exports = {
- port : 3000,
- address : '127.0.0.1',
-
- db : {
- url : 'mongodb://localhost/database'
- }
+ port : 3000
};
@@ -1,3 +1,12 @@
+var defaults = require('./defaults');
+
var env = process.env.NODE_ENV || 'development';
+var overrides = require('./' + env);
+
+for (var key in overrides) {
+ if (overrides.hasOwnProperty(key)) {
+ defaults[key] = overrides[key];
+ }
+}
-module.exports = require('./' + env);
+module.exports = defaults;
@@ -1,10 +1,5 @@
module.exports = {
- port : 3000,
- address : '127.0.0.1',
-
- db : {
- url : 'mongodb://localhost/database'
- }
+ port : 3001
};
View
@@ -0,0 +1,11 @@
+var config = require('../templates/app/config'),
+ should = require('should');
+
+describe('config', function() {
+ it('should define config using defaults and environment values', function() {
+ console.log(config);
+
+ config.address.should.equal('127.0.0.1'); // taken from defaults
+ config.port.should.equal(3000); // taken from development env
+ })
+});

0 comments on commit 8483884

Please sign in to comment.