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);
}
};