Whenever I run it on my web browser, I get an error that says “Uncaught error. Failed to fetch” Here’s the code that causes the problem.
useEffect(() => {
const fetchTweets = async() => {
const url = 'http://localhost:3000/tweet';
const authToken =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbklkIjozNX0.PhYEPigRB0Jpj6uW11-J8roshWrR4rfdfCPiXgS2gig'
const res = await fetch(url, {
headers: {
Authorization: `Bearer ${authToken}`
},
})
if (res.status !== 200){
console.log('Error fetching the api')
}
const data = await res.json()
console.log(data);
setTweets(data)
};
fetchTweets();
}, []);
I’ve ensured that the server is running and have even tested that it works with the ThunderClient vsCode extension. Please help.
I went to chatGPT, copilot, youtube… I even initialized CORS in the backend I built but still nothing. I copied notJust.dev youtube’s video on a twitter frontend integrated with the backend. He never got this error but now I do and I can’t resolve it no matter what I try. I even cloned his repo word for word and it still doesn’t work.
Efojensen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.