因此,当我向终点发送发帖请求时,一切正常。但是,当我发送放置和删除请求时,响应中出现了问题。这是我的一个端点(put)的代码
准确响应:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot PUT /api/auth/username</pre>
</body>
</html>
代码:
router.put('/username/:id', asyncMiddleware(async (req, res) => {
const user = await User.findByIdAndUpdate(req.params.id, {username: req.body.username, email: req.body.email, password: req.body.password}, {new: true})
if (!user) return res.status(404).send('User not found.')
res.send('User sucessfully updated.')
}))
请帮助解决这个问题。