Сложность в отправке пост запроса REACT
Есть функция которая кидает пост запрос:
let deleteInfo = async () => {
try {
const res = await axios.post("http://localhost:8080/deleteWorker" , { workerid })
.then((response) => {
if (response.data) {
console.log(response.data)
console.log("есть")
} else {
console.log("нет")
}
})
} catch (error) {
console.log(error)
}
}
На серверной части я пытаюсь ее обработать
app.post("/deleteWorker", (req, res) => {
let workerid = req.body.workerid
res.send({ message: "что-то" })
})
Однако я не понимаю почему post запрос завершается с ошибкой 404.
Слушаю порт:
app.listen(8080, () => {
console.log("was connected")
})
Ответ который приходит:
{
"message": "Request failed with status code 404",
"name": "AxiosError",
"stack": "AxiosError: Request failed with status code 404\n at settle (http://localhost:3000/static/js/bundle.js:48666:12)\n at XMLHttpRequest.onloadend (http://localhost:3000/static/js/bundle.js:47374:66)",
"config": {
"transitional": {
"silentJSONParsing": true,
"forcedJSONParsing": true,
"clarifyTimeoutError": false
},
"adapter": [
"xhr",
"http"
],
"transformRequest": [
null
],
"transformResponse": [
null
],
"timeout": 0,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"maxContentLength": -1,
"maxBodyLength": -1,
"env": {},
"headers": {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json"
},
"method": "post",
"url": "http://localhost:8080/deleteWorker",
"data": "{\"workerid\":2}"
},
"code": "ERR_BAD_REQUEST",
"status": 404
}
Источник: Stack Overflow на русском