mirror of
https://github.com/sstent/expressmongotest.git
synced 2026-01-26 00:52:11 +00:00
almost rebased
This commit is contained in:
18
chapter25/22_load_article_middleware.js
Normal file
18
chapter25/22_load_article_middleware.js
Normal file
@@ -0,0 +1,18 @@
|
||||
var Article = require('../../data/models/article');
|
||||
|
||||
function loadArticle(req, res, next) {
|
||||
Article.findOne({title: req.params.title})
|
||||
.populate('author')
|
||||
.exec(function(err, article) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
if (! article) {
|
||||
return res.send('Not found', 404);
|
||||
}
|
||||
req.article = article;
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = loadArticle;
|
||||
Reference in New Issue
Block a user