Problem
I'm running a react application on localhost:8000 on a MacOs and I would like to make it accessible from mobile devices connected to the same local network. The problem is that every connection to the local ip where localhost is hosted, is refused.
What I tried
I saw other people with similars problem as mine and I tried their solutions without any luck.
- I turned off the firewall
- I added a new firewall rule specific for node to allow incoming connections
- I tried to connect with and without having specified the port where localhost were hosted
- I edited the /etc/hosts [https://stackoverflow.com/questions/11005540/localhost-running-on-mac-can-i-view-it-on-my-android-phone]
- I turned off and on my WiFi [https://stackoverflow.com/questions/12657651/connect-device-to-mac-localhost-server]
What else can I do?
I'm running out of ideas and any suggestion is welcome! Thank you for your time in advance.
CodePudding user response:
find your local ip open ternimal and write command "ifconfig"
then connect you phone with wifi(the wifi you mac connected, not hotpot), and visit ip:8000
You need to learn some network related knowledge。In general, you should know that localhost is a special local (only valid for this computer) address, not a network accessible address. If you need network access, you need to find the network path, that is, when you access this computer, the address of this computer in the visitor's network, which is reflected here, when your mobile phone and computer are connected to a wifi at the same time, you can pass The router finds the ip address of the computer, and then you can access this ip address through the mobile phone. Note that if the visitor (mobile phone) is connected to the vpn, the vpn needs to be turned off
CodePudding user response:
Resolved
I found that since I'm using gatsby.js framework to develop my web app, It binds only the local ip. In order to get my website accessible from other local devices, connected to the same network, You have to define the local ip where the server should run.
In my case running gatsby develop -H 192.168.0.105 -p 8000
made my app visibile from all the other devices via 'http://192.168.0.105:8000'.
I'll leave the link where I found the solution to my problem: Testing site with gatsby develop from local LAN
I should have done a deeper research before asking and I'm sorry about that.
Hope this could help and thanks to all the people who passed by to help me.