0
votes

whenever I run "ionic cordova run android" and deploy the apk in the real device, I got error message: Access to XMLHttpRequest at 'http://XXXX/mobile/data/1/XXXX' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.

(this works in the ionic simulator by adding the proxy in config file, but not the real device).

Does anyone face this problem as well? here is my ionic info: ionic (Ionic CLI) : 4.2.1 (/usr/local/lib/node_modules/ionic) Ionic Framework : ionic-angular 3.9.2 @ionic/app-scripts : 3.2.0

Cordova:

cordova (Cordova CLI) : 8.1.2 ([email protected]) Cordova Platforms : android 7.1.2 Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.2.3, (and 8 other plugins)

System:

NodeJS : v8.12.0 (/usr/local/bin/node) npm : 6.4.1 OS : macOS High Sierra

2
Here is the detail about the CORS issue blog.ionicframework.com/…Kabir

2 Answers

0
votes

The backend has to enable other applications that access the API, this is done by enabling CORS.

In development you can use this plugin in chrome:

Allow-Control-Allow-Origin
https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi 

More in production the backend should fix that BUG..

0
votes

This is a server-side problem, you have to activate the CORS in the following link you will find the necessary configuration for your server.