Deployed Link not accepting post requests

Post requests working fine in local development server. Unfortunately, I receive a 500 server error when I try posting using the deployed link. Deployed link working perfectly for get requests but not for post requests (blogs).

const handleFormSubmit = async (e) => {

e.preventDefault();
setIsLoading(true);

const data = {
image: image,
title: title,
author: author,
content: content,
};

try {
const response = await fetch(‘https://weblog-server-cbto.onrender.com/blogs’, {
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/json’,
“Authorization”: Bearer ${user.token},
},
body: JSON.stringify(data),
});

if (!response.ok) {
  // Handle errors here, e.g., show an error message.
  console.error('Failed to create a blog:', response.statusText);
} else {
  const responseData = await response.json();
  dispatch({ type: 'CREATE_BLOG', payload: responseData });
  setImage('');
  setTitle('');
  setAuthor('');
  setContent('');
  setIsLoading(false);
  navigate('/');
}

} catch (error) {
// Handle any network or fetch-related errors here.
console.error(‘Fetch error:’, error);
}
};

Hi,

This seems it might be the same issue as the ticket you also opened? Let’s keep the conversation in one place (on the ticket). Then, you can update this post when we get to the solution.

Alan

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.