CORS while fetching data from api

i'm trying to fetch a data from geoDataSource. since i need to translate latitude and longitude into a city name. i got the api key and i try to fetch and the from origin 'http://127.0.0.1:5500' 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. this error comes. i tried mode: no-cors it didnt work but only gave me status 0. the problem here is it says CORS is from browser, and it is for security reason. so basically what i read says blocks the request from another domain if its not configured inside the server file or only the same domain can access to the server. so in order to access my domain has to be configured inside the domain or else i cant access the server! then why on earth the api website doesnt require my domain? and im currently just using live server inside the vscode , does it mean that i cant fetch api data since im requesting from local host? and i dont understnad why chrome blocks the localhost in the first place.
1 Reply
Matvey
Matvey5mo ago
If you fetch from the client you will leak your api key, just fetch from the server