CORS No 'Access-Control-Allow-Origin' header is present on the requested resource. Axios React

Viewed 37

my application is working when is in local host, I created a react app where im fetching data from api using axios I try to deployed it but in the actual page it only gives me an error related to axios Access to XMLHttpRequest at ""api"" from origin ""deployed page"" has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

 headers: {
'Access-Control-Allow-Origin' : '*'
} 

this wont work it gives me the same error and I tried

  headers: {
'Access-Control-Allow-Origin' : 'http://actual-page'
}

it still gives me the same error

axios 
.get('api', {
header: {
'Access-Control-Allow-Origin' : 'http://actual-page'
}
})
.then(res => {
setApiData(res.data)
})
.catch(error => console.log(error)

what else should I add or do

0 Answers
Related