(Express) 您好,我正在尝试通过邮递员向本地主机发出一个非常简单的 post 请求,但它在发送时卡住了。需要明确的是,我第一次尝试它时,它有效,但在添加了 mongoose 实现后,即使对更改进行了评论,它也不再起作用。
const router = require('express').Router();
router.post('/', (req, res) => {
console.log("Got here");
res.send("ciao");
});
app.listen(port, () => {
console.log("Server running on port: " + port);
});
If it was working correctly I'd see "Got here"
我正在使用适用于 Mac 的 postman 8.0.2 桌面应用程序,我尝试删除并重新安装。
编辑 我已经尝试创建另一个项目,它再次起作用,我会调查我做错了什么,并可能添加评论。
答案 0 :(得分:2)
将路由器作为中间件添加到快递中, 以下是您更新后的代码
const router = require('express').Router();
router.post('/', (req, res) => {
console.log("Got here");
res.send("ciao");
});
app.use('/', router);
app.listen(port, () => {
console.log("Server running on port: " + port)
});