Skip to content

Commit

Permalink
Fixing models auto loading bug
Browse files Browse the repository at this point in the history
  • Loading branch information
amoshaviv committed Sep 29, 2013
1 parent 0cfbafa commit fe50b41
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
7 changes: 3 additions & 4 deletions app/controllers/articles.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ exports.article = function(req, res, next, id) {
/**
* Create a article
*/
exports.create = function(req, res) {
exports.create = function(req, res) {
var article = new Article(req.body);
article.user = req.user;

Expand All @@ -32,8 +32,7 @@ exports.create = function(req, res) {
errors: err.errors,
article: article
});
}
else {
} else {
res.jsonp(article);
}
});
Expand Down Expand Up @@ -89,4 +88,4 @@ exports.all = function(req, res) {
res.jsonp(articles);
}
});
};
};
4 changes: 2 additions & 2 deletions config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ var _ = require('underscore');
// Load app configuration

module.exports = _.extend(
require(__dirname + '/../config/env/all.js'),
require(__dirname + '/../config/env/' + process.env.NODE_ENV + '.json') || {}) ;
require(__dirname + '/../config/env/all.js'),
require(__dirname + '/../config/env/' + process.env.NODE_ENV + '.json') || {});
4 changes: 2 additions & 2 deletions config/middlewares/authorization.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports.requiresLogin = function(req, res, next) {
if (!req.isAuthenticated()) {
return res.send(401, 'User is not authorized');
}
next();
next();
};

/**
Expand All @@ -30,4 +30,4 @@ exports.article = {
}
next();
}
};
};
2 changes: 1 addition & 1 deletion config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = function(app, passport, auth) {

//Setting up the users api
app.post('/users', users.create);

app.post('/users/session', passport.authenticate('local', {
failureRedirect: '/signin',
failureFlash: 'Invalid email or password.'
Expand Down
23 changes: 12 additions & 11 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@ var db = mongoose.connect(config.db);

//Bootstrap models
var models_path = __dirname + '/app/models';
var walk = function (path) {
fs.readdirSync(path).forEach(function (file) {
var newPath = path + '/' + file;
var stat = fs.statSync(newPath);
if (stat.isFile()) {
require(newPath);
}
else if (stat.isDirectory()) {
walk(newPath);
}
});
var walk = function(path) {
fs.readdirSync(path).forEach(function(file) {
var newPath = path + '/' + file;
var stat = fs.statSync(newPath);
if (stat.isFile()) {
if (/(.*)\.(js|coffee)/.test(file)) {
require(newPath);
}
} else if (stat.isDirectory()) {
walk(newPath);
}
});
};
walk(models_path);

Expand Down

0 comments on commit fe50b41

Please sign in to comment.