检查Express文档我在下面看到了这种解决方案:
app.all('/*', function(req, res) {
console.log('Intercepting requests...');
});
Run Code Online (Sandbox Code Playgroud)
它真正拦截了控制台上的请求和输出消息.问题是网站的执行过程没有停止,请求没有结束,似乎是在一种循环中.还有另一种方法可以在Express上模拟过滤器或者现在无法做到吗?
谢谢!
zem*_*rco 10
您必须将next函数作为参数添加,然后在完成日志记录后调用它
app.all('/*', function(req, res, next) {
console.log('Intercepting requests ...');
next(); // call next() here to move on to next middleware/router
})
Run Code Online (Sandbox Code Playgroud)