Reputation: 2249
I have a simple web service in my ionic app... it connects to remote server for simple tasks.
The proxy is setup in ionic like this:
"proxies": [{
"path": "/api",
"proxyUrl": "http://example.com/api"
}]
and the calls are to "/api". These resolve properly to http://example.com/api
in localhost browser (using ionic serve).
But in xcode, the url is resolved to:
file:///api
I can't find anything on this specifically. How show I be calling for ios?
Upvotes: 6
Views: 5231
Reputation: 175
I faced the same issue while running on Android device, The solution is simple, point to note here is the proxy we are using to handle the CORS issue and this is the issue only in perticular with the desktop browser, so while using ionic serve we need proxy and we dont need to use proxy for other devices. I have used below condition in the service to handle this with out doing any further code changes while building for any target platform.
var APIUrl = '/myproxies';
if (this.platform.is('core') == true){
APIUrl = '/myproxies';
}else{
APIUrl = 'http://api.sample.com/SomeSampleAPIProvider';
}
this.http.get(APIUrl+"/Json").map(res => res.json()).subscribe(
data => {.....
can refer this link to know usage details of this.platform
Upvotes: 3
Reputation: 21
This is the intended action. The ionic CLI proxy is only used for ionic CLI serve or run commands. More here: http://blog.ionic.io/handling-cors-issues-in-ionic/
The file:///api url will not trigger the Angular browser CORS pre-flight OPTIONS call, so you should be fine.
Any additional CORS issues you are experiencing would be on the server side.
Upvotes: 0