1

I am using Cordova to wrap my apps. As it can be, the app is running on the user's localhosts browser:

http://localhost:8100/

And I want to fetch data from the GCP but I receive an error of CORS (not ofcourse, ofcourse ;) (replace api_key with my real api_key):

Failed to load https://maps.googleapis.com/maps/api/directions/json?origin=Tel+Aviv&destination=Shoham&key=my_api_key: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.

Now the reason is obvious: they do not want to make the API data public and sneaky by thefts, but I do not find any way to set my app as approvable for fetching this data.

My app runs on Android and on iOS.

I have also tried, just for the test, to disable any limitations or restrictions via the GCP platform manager but still data is not getting delivered.

**

When I am trying to fetch the data via Node.js API (*backend), the data is available to come, but its making things more complicated and slow since you have to make two calls for the same data.

Is there any fix for this?

Raz
  • 1,910
  • 1
  • 15
  • 28
  • 1
    Take a look at : [CORS + Cordova](https://stackoverflow.com/questions/37398695/cors-cordova-issues-with-access-control-allow-origin/37398805) – Dimitrih Apr 25 '18 at 10:37
  • @Dimitrih this does not working. When I am adding the content security meta tag I can lots of errors that is prohibited to do so. – Raz Apr 26 '18 at 08:49

1 Answers1

0

I solved this issue.

Since the problem occurs only when doing it from localhost or livereload, I found to solve it by disable the CORS in the browser itself.

Install this: https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi

BTW notice that you will be probably get lots of errors from websites like Google and Facebook.

I found the best way to do this via a Node.js API serving as a proxy only during the development.

While changing the path to production, I call to Google apis directly and save time and bandwidth.

Raz
  • 1,910
  • 1
  • 15
  • 28