Ошибка при передаче данных на сервер
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 });
}
})