如何向每个高速公路路由函数添加中间件功能?大多数在数据库中被证明是CRUD的路由函数都有标准的前后语句--对于路由函数,是否有一种前后的方法。
app.route('/api/resources').all(projectsPolicy.isAllowed)
.get(resources.list)
.post(resources.create);发布于 2016-10-19 13:00:58
我想这是有可能的
app.route('/api/resources').all(projectsPolicy.isAllowed)
.get(before,resources.list,after)
.post(before,resources.create,after);功能在哪里?
发布于 2016-10-19 13:03:31
Express支持多个回调,如
app.get('/example/b', function (req, res, next) {
// do something here, like modify req or res, and then go on
next();
}, function (req, res) {
// get modified values here
});也可以写成
app.route('/api/resources', projectsPolicy.isAllowed).get(...假定中间件,isAllowed()函数调用next()等。
https://stackoverflow.com/questions/40131950
复制相似问题