CORS issue with ionic emulate

ionic emulate iOS runs on localhost and works fine.

ionic emulate iOS -l has two weird problems:

  1. It won’t use localhost - insists on using my Mac’s network address

  2. When the app tries to access the local file system (cordova.file.dataDirectory) using $http I get a CORS error: XMLHttpRequest cannot load [name of file] Cross origin requests are only supported for HTTP.

So it looks like the CORS problem is caused by using the network address instead of localhost. Any ideas?

What version of the CLI are you using? There was an update to the cli that should take care of this

You should have v 1.2.5

Interesting. I updated to 1.2.5 and now I have some new errors!

First of all:

Multiple addresses available.
Please select which address to use by entering its number from the list below:

but there is actually no list to choose from and the emulator launches using my network address rather than localhost.

And then at the end of the emulator startup I get this:

events.js:72
        throw er; // Unhandled 'error' event

The emulator launches despite the error but live reload isn’t working.

Hmm, what OS are you using? Mac, Windows, or Linux?

Please Mr. Hartington help me! I dont know whats going on… I am making a simple API request to feedly using the attached code. After installing the plugin to enable CORS in Chrome the api request is successful when i run ionic serve but when i run my app in the emulator it returns data:null and status:0 error message. What’s going on? How can I solve this?

$scope.feedlyApi = function() {

var req = {
method: ‘GET’,
url: “http://sandbox.feedly.com/v3/search/feeds”,
params: {
‘query’: ‘nursing’
},
headers: {
‘Content-Type’: ‘application/json’ ,
‘Access-Control-Allow-Origin’: ‘*’,
‘Access-Control-Allow-Methods’: ‘POST, GET, OPTIONS’,
‘Access-Control-Allow-Headers’:‘X-Requested-With’
}
}

$http(req).success(function(res) {
console.log(res);
console.log(‘Success’, angular.toJson(res.data));
}).error(function(err){
console.error(angular.toJson(err))
})
}