I want to fetch some data from an API. But CORS policy is blocking the access for fetching
const fetchApi = async () => {
const result = await fetch('https://api.themoviedb.org/3/discover/movie?',
{
method: "GET",
headers: {
"Access-Control-Allow-Headers": "Content-Type, Authorization",
"Access-Control-Allow-Origin": "http://localhost:3000",
"Access-Control-Allow-Methods": "POST,GET,OPTIONS",
'Access-Control-Allow-Credentials': true,
accept: 'application/json',
Authorization: 'Bearer API_KEY',
'callback' : 'test'
}
})
}
useEffect(() => { fetchApi() }, [])
As of my limited knowledge, header data is not getting passed.
I tried two things :
- Instead of passing API key through header, I added api key with url. It gave result. But my requirement is to pass API key via header.
2.Tried adding access-controls in header. Still the error remains the same
Even after specifying the headers, CORS is blocking the request. I think the header data is not passing to the gateway. Someone please healp me with this. I can't figure out know what went wrong