I am trying to make a fetch request for my React app, but I keep getting this CORS error. The request works fine in Postman. I have added the Access-Control-Allow-Origin header. I also tried adding mode: 'no-cors', but that did not work either. I can't find anything online for any other solutions. This is the code I'm using:
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer <MY_API_KEY>");
myHeaders.append("Cookie", "__cfduid=db290300ecfe95ec1fe3bc92c388c3c991586618117");
myHeaders.append("Access-Control-Allow-Origin", "*");
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://api.yelp.com/v3/businesses/search?location=Houston", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));