如何将路由器/中间件添加到羽毛应用程序?



我已经在我的羽毛应用程序中添加了路由器,如下所示

app.use('/test', (req, res) => {
res.json({
message: 'Hello world from Express middleware'
});
});

当我从邮递员向 http://localhost:3030/test 发送获取请求时,应用程序正在 http://localhost:3030/运行,我收到以下错误

{
"name": "NotFound",
"message": "Page not found",
"code": 404,
"className": "not-found",
"data": {
"url": "/test"
},
"errors": {}
}

我该如何解决这个问题?谢谢期待。

我认为你的代码应该是:

app.get('/test', (req, res) => {
res.json({
message: 'Hello world from Express middleware'
});
});

最新更新