HTTPS request CORS problem even if ionic cordova run ios --prod

Hi all,

I solved the CORS problem by using proxies on emulator, i.e. for ionic cordova emulate ios -c. However, on real device, when I did ionic cordova run ios --prod, it still met the CORS problem. In fact, ionic cordova run ios -c worked on real device, as proxy configs were added.

Any idea will be appreciated!

What CORS error are you facing? The general solution for any CORS issue is to have the server you are making a request to to respond with the appropriate header: https://enable-cors.org/server.html

There are ways of getting around CORS, but it’s better to just set up the server properly.

It got unknown url error. Yeah, when I set up the server to handle cors correctly, the problem is gone. However, if I understand correctly, the CORS problem occurs only when running in a browser, and should not happen when running natively on the device.

The application still runs inside of an embedded browser when running natively on the device, so CORS still applies unless you proxy the requests through native code using the HTTP plugin.

But https://blog.ionicframework.com/handling-cors-issues-in-ionic/ suggests ionic run should not have problem?

The article is from 2015, at that point UIWebView would have been used which doesn’t enforce CORS.

I see. Thanks for the answer!

using HTTP Native plugin solves CORS automatically.

Also this is very helpful library, you only have to install it and dont change anything, it’ll do it for you and just use Angular HttpClient as you’d normally do: https://github.com/sneas/ionic-native-http-connection-backend

What this plugin does is detect if youre in web or a device and then use HTTP Native or Angular’s HTTP. It will also let you use things like interceptors from Angular even if you’re on the device. It’s awesome.

Thanks for the info! Will take a look.