I have a basic react app communicating with a SQL database and have a demo API running with Flask. I know my API works with manual confirmation on Postman.
I am simply trying to post data to my database via my verified API. However, I run into issues with fetch based on the headers in my post method. Below is my current code:
const request = new Request("http://155.98.25.80:8000/user",
{method: 'POST',
headers:{'Content-Type': 'application/json', 'Access-Control-Allow-Origin': "http://localhost:3000/",
'Accept':'application/json'},
body: user_data,
mode:'cors',
});
console.log(request)
fetch(request)
.then(response => {
if (response.status === 200) {
return response.json();
}
else {
throw new Error('Something went wrong on api server!');
}
})
.then(response => {
console.debug(response);
// ...
}).catch(error => {
console.error(error);
});
}
It is a pretty standard POST request that is triggered on a button click. When I make this request, I can see the API returns a 200 code, meaning it went through to the database. However, in my browser (Chrome) console, I receive the following error: TypeError: Failed to fetch.
I am pretty lost here. I know my post request is going through, but it seems that the return is failing with the response. I have read many of the other posts dealing with this issue, and I am not sure what is going wrong with my app. Any help would be great.


