@aleshaykovlev
html, css, js, node, webpack, sass, react

Failed to load resource: the server responded with a status of 404 (Not Found)?

Ошибка при передаче данных на сервер

client:
function submitForm(e) {
    e.preventDefault();

    const res = {
      id: window.location.pathname.replace(/\/profile\//, ''),
      images: images_of_post
    };

    fetch(`http://localhost:3000/profile/post/${res.id}`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(res)
    });
  }


server:
router.post('/post/:id', async (req, res) => {
  try {
    const { text, images } = req.body;
    const findUser = await User.findById(req.params.id);

    const newPost = new Post({
      userId: findUser._id,
      user: findUser,
      images: images,
      text,
      date: new Date(),
      comments: []
    })

    await newPost.save();
    res.redirect('/');
  } catch (e) {
    res.status(404).json({ message: e.message });
  }
})
  • Вопрос задан
  • 890 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы