我正在使用Node.js和Express。现在我需要对所有请求执行一项常见操作,例如检查cookie。
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
});
在所有请求中,检查cookie是一个普遍的行为。那么如何在所有app.get中执行此操作,而不重复cookie检查代码呢?
有什么建议可以解决这个问题吗?提前感谢。