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

Commit 6b57516

Browse files
committed
ensure NODE_ENV is valid, default regex for walk
1 parent f17c48c commit 6b57516

File tree

6 files changed

+23
-20
lines changed

6 files changed

+23
-20
lines changed

config/config.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
'use strict';
22

3-
var _ = require('lodash');
3+
var _ = require('lodash'),
4+
utilities = require('./utilities');
45

5-
// Load app configuration
6-
module.exports = _.merge(require(__dirname + '/../config/env/all.js'), require(__dirname + '/../config/env/' + process.env.NODE_ENV + '.js') || {});
6+
process.env.NODE_ENV = ~utilities.walk('./config/env', /(.*)\.js$/).map(function(file) {
7+
return file.split('/').pop().slice(0, -3);
8+
}).indexOf(process.env.NODE_ENV) ? process.env.NODE_ENV : 'development';
9+
10+
// Load app configurations
11+
module.exports = _.extend(
12+
require('./env/all'),
13+
require('./env/' + process.env.NODE_ENV) || {}
14+
);

config/express.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ var express = require('express'),
99
flash = require('connect-flash'),
1010
config = require('./config'),
1111
consolidate = require('consolidate'),
12-
swig = require('swig'),
1312
path = require('path'),
1413
utilities = require('./utilities');
1514

@@ -18,7 +17,7 @@ module.exports = function(db) {
1817
var app = express();
1918

2019
// Initialize models
21-
utilities.walk('./app/models', /(.*)\.(js$|coffee$)/).forEach(function(modelPath) {
20+
utilities.walk('./app/models').forEach(function(modelPath) {
2221
require(path.resolve(modelPath));
2322
});
2423

@@ -58,7 +57,7 @@ module.exports = function(db) {
5857

5958
// Application Configuration for development environment
6059
app.configure('development', function() {
61-
// Enable logger
60+
// Enable logger
6261
app.use(express.logger('dev'));
6362

6463
// Disable views cache
@@ -106,7 +105,7 @@ module.exports = function(db) {
106105
app.use(express.static(config.root + '/public'));
107106

108107
// Load Routes
109-
utilities.walk('./app/routes', /(.*)\.(js$|coffee$)/).forEach(function(routePath) {
108+
utilities.walk('./app/routes').forEach(function(routePath) {
110109
require(path.resolve(routePath))(app);
111110
});
112111

@@ -133,4 +132,4 @@ module.exports = function(db) {
133132
});
134133

135134
return app;
136-
};
135+
};

config/passport.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = function() {
2121
});
2222

2323
// Initialize strategies
24-
utilities.walk('./config/strategies', /(.*)\.(js$|coffee$)/).forEach(function(strategyPath) {
24+
utilities.walk('./config/strategies').forEach(function(strategyPath) {
2525
require(path.resolve(strategyPath))();
2626
});
27-
};
27+
};

config/utilities.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ var fs = require('fs');
99
var _walk = function(root, includeRegex, excludeRegex, removePath) {
1010
var output = [];
1111
var directories = [];
12+
includeRegex = includeRegex || /(.*)\.(js|coffee)$/;
1213

13-
// First read through files
14+
// First read through files
1415
fs.readdirSync(root).forEach(function(file) {
1516
var newPath = root + '/' + file;
1617
var stat = fs.statSync(newPath);
@@ -35,4 +36,4 @@ var _walk = function(root, includeRegex, excludeRegex, removePath) {
3536
/**
3637
* Exposing the walk function
3738
*/
38-
exports.walk = _walk;
39+
exports.walk = _walk;

karma.conf.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
var utilities = require('./config/utilities');
77

88
// Grabbing module files using the walk function
9-
var modulesJSFiles = utilities.walk('./public/modules', /(.*)\.(js)/, null, null);
9+
var modulesJSFiles = utilities.walk('./public/modules', /(.*)\.js$/);
1010

1111
// Karma configuration
1212
module.exports = function(config) {
@@ -63,4 +63,4 @@ module.exports = function(config) {
6363
// If true, it capture browsers, run tests and exit
6464
singleRun: true
6565
});
66-
};
66+
};

server.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
'use strict';
22

3-
/**
4-
* First we set the node enviornment variable if not set before
5-
*/
6-
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
7-
83
/**
94
* Module dependencies.
105
*/
@@ -31,4 +26,4 @@ app.listen(config.port);
3126
exports = module.exports = app;
3227

3328
// Logging initialization
34-
console.log('Express app started on port ' + config.port);
29+
console.log('Express app started on port ' + config.port);

0 commit comments

Comments
 (0)