mirror of
https://github.com/sstent/expressmongotest.git
synced 2026-01-25 16:42:00 +00:00
18 lines
404 B
JavaScript
18 lines
404 B
JavaScript
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; |