App on my phone can't call backend running on localhost

Hi all

What i’m trying to do is:

Have my backend running on localhost: 3601, and it’s not running on a dedicated server, just my laptop;
Have “http://localhost:3601” as “apiurl” in my settings.json;
When building use “http://localhost:3601” after --server;
Compile my code to run on my android;

The login page shows, but when I try to login which calls the backend login
function, it just returns “connection lost” despite knowing the apiurl.

What am I doing wrong here? I assume it’s some parameter i should
set when I build my code but I can’t quite figure out which one that is.

Thanks in advance for any help!

Hello, did you make sure that you’re on the same wifi network and your backend Meteor server is pingable from the phone?

1 Like

Wouldn’t “http://localhost:3601 on the phone just point at the phone?

Have you tried passing a static IP address where the phone can reach the server?

2 Likes

Hi I didn’t know that, maybe my phone simply can’t reach the backend, which is my laptop. I’ll check, thank you for your advice.

1 Like

Hi I’ve not tried passing a static IP, i thought since the backend is just running on my laptop giving it localhost:3601 should be sufficient, which doesn’t seem to be the case. Anyway thx for your reply

If you want to access meteor from another machine on your network you need to enable this when starting meteor. This is done by setting the ROOT_URL environment variable. Localhost only works on the machine running meteor.

E.g ROOT_URL=192.192.192.192 meteor

Windows env variable is different and I think you need to use ‘set’ to configure.

See the docs in meteor guide https://galaxy-guide.meteor.com/environment-variables.html#common-env-variables

2 Likes

Hi thanks for your reply, do I give the “ROOT_URL=192.192.192.192” to my front end app running on my phone or my backend? I’m not really sure in this case which one you are talking about, from “if you want to access meteor from another machine” is sounds like I should give this to my backend running on my laptop? Also should I replace 192.192.192.192 with my backend local ip or is 192.192.192.192 necessary?

Apply it to the backend when starting meteor. It should be the ip of your backend laptop to which your phone must also be connected Meteor by default only broadcasts to the local host (your laptop) and any other device on your network cannot access the meteor server.

2 Likes

Hi thanks, I got the problem solved by combining your answer with another answer from an issue report on git: https://github.com/meteor/meteor/issues/9928

The solution:

Use command “ifconfig |grep inet” to find the ip address that looks like 192.168.., it’s shown after “inet”.

On my server side, which is running on my laptop:
ROOT_URL=“http://192.168.0.100:3601” meteor -p 3601

On my client side, which is running on my phone, in settings-dev.json:
“apiurl” : “http://192.168.0.100:3601

And everything is working now. Seems that if you give it anything other than 192.168.. it
will block the incoming request, even if the ip address makes perfect sense.

Thanks everyone!