I created a cloudflare worker for adding CORS headers to prevent my flutter web app from getting CORS errors. I copied the code from the cloudflare example
(https://developers.cloudflare.com/workers/examples/cors-header-proxy
). The only thing that I changed is to change the API_URL to a valid Google Maps API url (for testing). Now if I type in the url of my worker (https://corsproxy.info-sunclicker.workers.dev/
) in the browser, I see that I get a valid response without CORS proxy. But with CORS proxy and CORS proxy + preflight I get a response with this error message: “You must use an API key to authenticate each request to Google Maps Platform APIs”
It is strange because without cors proxy I get this valid response, so the API key is definitely correct: {“results”:[{“address_components”:[{“long_name”:“New York City”,“short_name”:“New York City”,“types”:[“locality”,“political”]},{“long_name”:“New York”,“short_name”:“NY”,“types”:[“administrative_area_level_1”,“political”]},{“long_name”:“USA”,“short_name”:“US”,“types”:[“country”,“political”]}],“formatted_address”:“New York City, New York, USA”,“geometry”:{“bounds”:{“northeast”:{“lat”:40.9175771,“lng”:-73.70027209999999},“southwest”:{“lat”:40.4773991,“lng”:-74.25908989999999}},“location”:{“lat”:40.7127753,“lng”:-74.0059728},“location_type”:“APPROXIMATE”,“viewport”:{“northeast”:{“lat”:40.9175771,“lng”:-73.70027209999999},“southwest”:{“lat”:40.4773991,“lng”:-74.25908989999999}}},“place_id”:“ChIJOwg_06VPwokRYv534QaPC8g”,“types”:[“locality”,“political”]}],“status”:“OK”}
I also tried a MapQuest API url which also requires an API key, but I get the same result there.
Does anybody know how I can fix this error?
Thanks in advance!