I created A vite-react app, in my App I'm trying to fetch a public API
https://api.football-data.org/v4/matches
// This does not work
But I get
Access to fetch at 'https://api.football-data.org/v4/matches' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
I know what the error means, but this is a public API and I'm confused about where to add CORS.
But I noticed I could fetch another public API successfully using the same method.
http://swapi.dev/api/planets/1/
// This API works
page.tsx
const fetchAllCompetitions = async () => {
const res = await fetch("https://api.football-data.org/v4/matches");
return res.json();
};
const { data } = useQuery("users", fetchAllCompetitions);
console.log(data);
Kinda confused.
is there anything I would have to set on the vite-config file?