我正在使用带有express的节点js.现在我需要对所有请求执行常见操作.饼干检查
app.get('/',function(req, res){
//cookie checking
//other functionality for this request
});
app.get('/show',function(req, res){
//cookie checking
//other functionality for this request
});
Run Code Online (Sandbox Code Playgroud)
这里cookie检查是所有请求的常见操作.那么如何在不重复所有app.get中的cookie检查代码的情况下执行此操作.
解决此问题的建议?提前致谢
查看路由中间件上的快速文档中的loadUser示例.模式是:
function cookieChecking(req, res, next) {
//cookie checking
next();
}
app.get('/*', cookieChecking);
app.get('/',function(req, res){
//other functionality for this request
});
app.get('/show',function(req, res){
//other functionality for this request
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1905 次 |
| 最近记录: |