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

Commit

Permalink
ensure NODE_ENV is valid, default regex for walk
Browse files Browse the repository at this point in the history
  • Loading branch information
fyockm committed Mar 27, 2014
1 parent f17c48c commit 6b57516
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
14 changes: 11 additions & 3 deletions config/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
'use strict';

var _ = require('lodash');
var _ = require('lodash'),
utilities = require('./utilities');

// Load app configuration
module.exports = _.merge(require(__dirname + '/../config/env/all.js'), require(__dirname + '/../config/env/' + process.env.NODE_ENV + '.js') || {});
process.env.NODE_ENV = ~utilities.walk('./config/env', /(.*)\.js$/).map(function(file) {
return file.split('/').pop().slice(0, -3);
}).indexOf(process.env.NODE_ENV) ? process.env.NODE_ENV : 'development';

// Load app configurations
module.exports = _.extend(
require('./env/all'),
require('./env/' + process.env.NODE_ENV) || {}
);
9 changes: 4 additions & 5 deletions config/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ var express = require('express'),
flash = require('connect-flash'),
config = require('./config'),
consolidate = require('consolidate'),
swig = require('swig'),
path = require('path'),
utilities = require('./utilities');

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

// Initialize models
utilities.walk('./app/models', /(.*)\.(js$|coffee$)/).forEach(function(modelPath) {
utilities.walk('./app/models').forEach(function(modelPath) {
require(path.resolve(modelPath));
});

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

// Application Configuration for development environment
app.configure('development', function() {
// Enable logger
// Enable logger
app.use(express.logger('dev'));

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

// Load Routes
utilities.walk('./app/routes', /(.*)\.(js$|coffee$)/).forEach(function(routePath) {
utilities.walk('./app/routes').forEach(function(routePath) {
require(path.resolve(routePath))(app);
});

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

return app;
};
};
4 changes: 2 additions & 2 deletions config/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = function() {
});

// Initialize strategies
utilities.walk('./config/strategies', /(.*)\.(js$|coffee$)/).forEach(function(strategyPath) {
utilities.walk('./config/strategies').forEach(function(strategyPath) {
require(path.resolve(strategyPath))();
});
};
};
5 changes: 3 additions & 2 deletions config/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ var fs = require('fs');
var _walk = function(root, includeRegex, excludeRegex, removePath) {
var output = [];
var directories = [];
includeRegex = includeRegex || /(.*)\.(js|coffee)$/;

// First read through files
// First read through files
fs.readdirSync(root).forEach(function(file) {
var newPath = root + '/' + file;
var stat = fs.statSync(newPath);
Expand All @@ -35,4 +36,4 @@ var _walk = function(root, includeRegex, excludeRegex, removePath) {
/**
* Exposing the walk function
*/
exports.walk = _walk;
exports.walk = _walk;
4 changes: 2 additions & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
var utilities = require('./config/utilities');

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

// Karma configuration
module.exports = function(config) {
Expand Down Expand Up @@ -63,4 +63,4 @@ module.exports = function(config) {
// If true, it capture browsers, run tests and exit
singleRun: true
});
};
};
7 changes: 1 addition & 6 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
'use strict';

/**
* First we set the node enviornment variable if not set before
*/
process.env.NODE_ENV = process.env.NODE_ENV || 'development';

/**
* Module dependencies.
*/
Expand All @@ -31,4 +26,4 @@ app.listen(config.port);
exports = module.exports = app;

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

0 comments on commit 6b57516

Please sign in to comment.