考虑以下代码片段:
var count = 0;
function a(req, res, next){
count++;
console.log(count);
next();
};
app.get('*', a);
app.get("/", routes.index);
app.get("/foo", routes.foo);
函数 a() 将为每个定义的路由执行,在本例中为 2,每个 http 请求。count 变量只是为了说明。因此,如果我定义了 100 条路由,则 a() 将对站点的每个请求执行 100 次。这是预期的行为,还是我做错了什么?谢谢!