Sunday, May 5, 2024
HomeRuby On RailsThe way to Preview localhost Web site on Cellular Cellphone

The way to Preview localhost Web site on Cellular Cellphone



Scrolling a website on phone next to a computer
Picture by Maxim Ilyahov on Unsplash

Are you trying to preview your web site in your cellular (or pill) whereas growing it in your laptop? Or vice-versa? Possibly you need to get a “actual really feel” of how the web site works and appears immediately on the machine. Then, you’re in for a deal with. In the present day, we’ll present how one can go to the web site hosted on localhost immediately out of your cellular or pill.

Step 1: Join your machine to the identical community

In case you have a number of WiFi networks, guarantee your laptop and machine are on the identical WiFi. This step is important.

Step 2: Discover your laptop’s native IP handle

Your laptop has a public IP and a neighborhood IP handle. We want a native IP handle, IPv4, to be extra exact. You should be asking – “How do I discover my native IP handle?“. Right here’s how you are able to do it on completely different working techniques:

Mac OS

  1. Open System Preferences -> Community
  2. Subsequent to the Standing, it is best to see the IP handle. It ought to write out – “WiFi is linked to YOUR_WIFI_NAME and has the IP handle YOUR_LOCAL_IP.” See the way it seems to be within the screenshot under:

Mac OS network settings
The native IP handle is underlined in purple.

Linux

  1. Run in your terminal hostname -I. Or, run ifconfig | grep "inet " | grep -v 127.0.0.1

Home windows

  1. Choose Begin > Settings > Community & web > Wi-Fi after which choose the Wi-Fi community you’re linked to.
  2. Below Properties, search for your IP handle listed subsequent to IPv4 handle.

Nice, now that we bought our laptop’s native IP handle, we have to run our app.

Step 3. Get the port quantity

For those who’re working a Rails app, the port is often 3000, and you’ll entry your app within the http://localhost:3000.

💡 In my case, I needed to bind the server to 0.0.0.0. I run a Gatsby web site, so for me, it was gatsby develop --host 0.0.0.0, which runs the server that listens on the 8000 port.

No matter method you run your server, make certain to make use of the PORT from http://localhost:PORT – the place the server listens for incoming requests.

Step 4: Open your different machine’s browser

In your cellphone or pill, open your browser of alternative and kind in http://YOUR_LOCAL_IP:PORT – which in my case was http://192.168.1.30:8000.

For those who’re working a server on http://localhost:3000, and your IP is 192.168.1.10, then it’s good to go to http://192.168.1.10:3000 in your cellular or pill.

That’s it

Now you can browse your web site immediately out of your different machine when you develop on the pc. How neat!

Now, you’ll be able to take a look at cellular and pill views on actual gadgets. That’s for those who want to take action.

Thanks for following alongside, and catch you within the subsequent one.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments