I have a problem with a fetch on an API, here is my code:
const OPTIONS = {
method: 'GET',
headers: {
'X-Auth-Token': process.env.FOOT_KEY,
}
};
export async function setLeagues() {
const countries = [
{
name: "Ligue 1",
leagues_id: 2015
},
{
name: "Premier League",
leagues_id: 2021,
},
{
name: "Bundesliga 1",
leagues_id: 2002,
},
{
name: "Primera Division",
leagues_id: 2014,
},
]
let allLeagues = [];
for (const country of countries) {
const { name, leagues_id } = country;
const response = await fetch(
`http://api.football-data.org/v2/competitions/${leagues_id}`,
OPTIONS
);
const data = await response.json();
allLeagues.push(data);
}
return {
type: "SET_LEAGUES",
payload: allLeagues
}
}
But I have a console error :
However when I make the request with postman the returned response contains well: Access-Control-Allow-Origin: *.
Finally the error seems to be present only on firefox but not on chrome.
I try to fetch this API : football-data.org/docs/v2/index.html#_cors_handling, who is CORS enabled.
Thanks you for your help !