当我通过Axios向我的Express API发送请求时,GET和POST请求正确响应,而PUT和DELETE则不响应。 这不是代码问题,因为我所有的测试都通过了,我相信这与CORS有关
我已经安装了morgan
npm软件包以将请求记录到服务器。
GET和POST正常工作,但是PUT / DELETE不能正常工作,这些路由处理程序中的console.log()消息甚至都不会显示!
PUT和DELETE的响应为404
app.js
app.use(cors())
router.js
router.delete('/', (req, res) => {
// this log statement does not show up!
console.log('request recieved')
Controller.DeleteItem(req.body.data.title).then(() => {
res.redirect('/')
}
}
console output
OPTIONS 204
DELETE 404
request
axios.delete('http://localhost:5000/', {
data: {
title: title
}
}
答案 0 :(得分:0)
这是在SO之外讨论的:问题是放置和删除路径放置在发布路径内部,当在上下文中查看整个代码时,缩进(此处未出现)很明显。