3

I'm trying to create an application that uses rest api. The backend is on my local machine, so I've got this

127.0.0.1   api.mail.my

in /etc/hosts

In the application I've got the following:

var messageResource = $resource('http://api.mail.my/messages/:folder/:id');

which works ok, when accessing this app via browser.

But how do I make this app to access the resource, when it's being run in an emulator (cordova emulate android)?

1 Answer 1

3

when you use localhost on the emulator, it refers to the ip of the emulator itself, not the one of your computer.

You have to get the local ip of your computer and use it instead of localhost or 127.0.0.1.

4
  • Thanks! But thats's a bit complicated since I'm behind a corporate proxy.
    – k102
    Commented Mar 13, 2015 at 10:50
  • What's complicated? the proxy is between your computer and outside, should not be between different machines in local network.
    – QuickFix
    Commented Mar 13, 2015 at 10:56
  • Well, I've changed this host to my computers ip and now have another issue: I can connect to http://10.10.0.53 but not to http://10.10.0.53:3000 neither by my app nor the browser. What shoud I look for?...
    – k102
    Commented Mar 13, 2015 at 13:15
  • check the firewall of your computer to allow access to the ports you need (or temporarilly disable the firewall)
    – QuickFix
    Commented Mar 13, 2015 at 14:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.