app.use() 不记录任何传入请求
我通过 Express 和路由器设置了一些 api 调用。我正在尝试调试并了解路由器的工作原理。我设置了一个记录器,并尝试记录所有 api 调用。但是,这些呼叫永远不会被记录。所有 api 端点都被调用,并且应用程序按预期工作。下面是我正在尝试做的事情的一个例子。有人可以让我知道这里可能缺少什么吗?
const logger = require('./config');
const app = express();
// routes needed for the app
app.use(require('./routes/apis'));
app.use('/api', (req, res, next) => {
logger.info('in /api call');
});
I have a few api calls set up via express and router. I am trying to debug and understand the working of the router. I have a logger set up, and trying to log all the api calls. However, the calls are never logged. All the api endpoints get called and the application works as expected though. Below is an example of what I am trying to do. Can someone please let me know what could be missing here?
const logger = require('./config');
const app = express();
// routes needed for the app
app.use(require('./routes/apis'));
app.use('/api', (req, res, next) => {
logger.info('in /api call');
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要更改中间件的顺序:
you need to change the order of the middleware: