I am trying to fetch data using Axios, (URL: http://3.134.99.170:4000/upcomingMovies)
I am always getting this error:
Access to XMLHttpRequest at 'http://3.134.99.170:4000/upcomingMovies' from origin 'http://localhost:9000' 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.
I have tried using fetch and superagent also, but the same error again.
Also, this is my code:
axios({
method: "GET",
url: "http://3.134.99.170:4000/upcomingMovies",
headers: {
'Access-Control-Allow-Headers': 'Content-Type, Accept, Access-Control-Allow-Origin, Access-Control-Allow-Methods',
'Access-Control-Allow-Origin' : '*',
'Access-Control-Allow-Methods' : 'GET,PUT,POST,DELETE,PATCH,OPTIONS',
"Content-type": "application/json"
}
})
.then((response) => {
setUpcomingMovies(response)
})
.catch((error) => {
console.log(error)
})