Vote count:
2
I recently started working on MEAN stack and using expressjs on the server. In number of tutorials I have read, express js routes are used as
var post = require('./routes/post');
app.get('/post/:post_id', post.get);
app.post('/post/:post_id/comment', post.addComment);
app.del('/post/:post_id/comment', post.removeComment);
But I started using boiler plate code of MEAN.io where the routes are used as
'use strict';
// Articles routes use articles controller
var articles = require('../controllers/articles');
var authorization = require('./middlewares/authorization');
// Article authorization helpers
var hasAuthorization = function(req, res, next) {
if (req.article.user.id !== req.user.id) {
return res.send(401, 'User is not authorized');
}
next();
};
module.exports = function(app) {
app.route('/articles')
.get(articles.all)
.post(authorization.requiresLogin, articles.create);
app.route('/articles/:articleId')
.get(articles.show)
.put(authorization.requiresLogin, hasAuthorization, articles.update)
.delete(authorization.requiresLogin, hasAuthorization, articles.destroy);
// Finish with setting up the articleId param
app.param('articleId', articles.article);
};
What does get and post both defined on single path do? Actually even to get articles we need to be authorized though authorization.requiresLogin is not mentioned on get of '/articles'.
asked 57 secs ago
Aucun commentaire:
Enregistrer un commentaire