Answer the question
In order to leave comments, you need to log in
Why does this post request give a 404 even though the route is routed?
Tell me, what is the error when sending a post request to the server, it gives 404 , I try to make my request to add information to the database array by analogy from the example, but I don’t understand what the error is, when adding an item into the box, I send a request to the server, in theory there should be routing of this request, and with such a request, I would like the data to be entered into the user's array. Tell me how to do it right, here is the code that processes the request, and here are the repositories https://github.com/ChekhDanil/todofproj
function addTask(text, id) {
const requestOptions = {
method: 'POST',
headers: authHeader(),
body: JSON.stringify(text)
};
return fetch(`${config.apiUrl}/tasks/${id}`, requestOptions)
.then(handleResponse);
}
router.post('/tasks/:id', addTask);
function addTask(req, res, next) {
userService.addTask(req.body,req.params.id)
.then(() => res.json({}))
.catch(err => next(err));
}
async function addTask (text,id)
{
const user= await User.findById(id);
if (user) {
user.todo.push({
id:"155",
task:text,
isCompleted:false,
})
};
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question