k102
k102

Reputation: 8079

Cordova android emulator - how to use local host?

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)?

Upvotes: 3

Views: 2731

Answers (1)

QuickFix
QuickFix

Reputation: 11721

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.

Upvotes: 3

Related Questions