$http requests when using live reload

When using ionic emulate ios I can easily make an http request with code:

But when I emulate ios with live reload enabled, all http requests error with a response of null. I have looked online for similar issues but I can’t seem to easily find the issue.

Does anyone know why live reload is not able to make requests that work seamlessly when not using live reload?

Ionic cli is up to date with ionic 1.2.4 installed in the project.

Thanks in advance.

Any errors in the console for the requests?

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

@Sujan12 is correct, have you tried using Safari remote debugging?

Google that topic to find out how.

That’s the only reliable way to determine possible errors on your iOS based smartphone.

One last thing, have you used a white list plugin?

1 Like

haha @Gajotres I was just coming back to say that I had solved the problem and it was through the means which you just recommended. Which I would have know about that tool earlier.

Thanks @Sujan12, your recommendation to look at the logs encouraged me to start my search to find the debugger myself which @Gajotres recommended.

So as @Gajotres suggested the emulator was throwing errors but these were not being shown by the console output of livereload. After opening the safari debugger I quickly realized that this was a simple cors issue on my node server. I had already added localhost:8100 to accept ionic requests, but through the magic of live reload, requests from the emulator do not appear to come from localhost but from your local ip address. To allow for all local ionic requests sent to your server locally simply add the following:

// Assuming that you are running a node express server, adding this to your config
// get local ip
require(‘dns’).lookup(require(‘os’).hostname(), function (err, addr, fam) {
process.env.localIp = addr;

// Add this to your routes
// dynamically allow cors from all local ionic servers
var cors = {
origin: [“http://”+process.env.localIp+":8100"],
default: “http://localhost:8100
var origin = (cors.origin.indexOf(req.headers.origin) > -1) ? req.headers.origin : cors.default;
res.header(“Access-Control-Allow-Origin”, origin);