Localhost running on mac.. Can I view it on my Android phone?

前端 未结 11 1188
遥遥无期
遥遥无期 2021-01-30 04:59

Running a ruby on rails project on my mac. I need to test it on my android phone. Is there a way to view my mac localhost on my android phone?

相关标签:
11条回答
  • 2021-01-30 05:44

    after reading this thread (and the suggestions working!) I put together a single guide to solving this issue. This link to that guide that has screenshots for every step and where to look. Or the text is pasted below. Thank you for the help!

    First off, both your phone and laptop must be connected to the same WiFi network. If you're using your phones mobile hotspot, it will still work. However, make sure to connect both devices to the same network before moving forward.

    Next, collect your phones IP address. To do so, I use the Network Info II app. There is most definitely another way to accomplish this. However, Network Info II works as needed and is document for this tutorials sake.

    Now open the terminal on your computer (don't worry about which directory you're within) and run the command sudo nano /etc/hosts/. After entering your system password, you'll see near the top of the terminal a string of numbers with the word localhost following. Localhost is in fact just an alias for your computer's own server address so that when you go to localhost in a browser it simply routes the http request to your local machine. In order to tie your phone into this loop, enter its IP address right between the string of numbers and Localhost.

    To save this, hit control + X and then Y when prompted to save. After that, the enter key will bring you back to the standard command line.

    Open a second tab in the terminal and launch a local server. I've only tested this using a simple python server, which can be run by running in the terminal python -m SimpleHTTPServer 8000. However, I'm assuming that you can launch any local server you like, being that all you'll need to reference is the port number. If you do use the simple python server, that port number is 8000.

    Run ifconfig in the terminal. This will bring up a slew of information, to which you should scroll about halfway down. What you are looking for is a string of numbers that follow after an inet and before netmask within either the en0: or en1: key.

    Done! On your Android, open up a browser and visit the inet number, followed by a colon (:) and the port number.

    0 讨论(0)
  • 2021-01-30 05:44

    As mentioned in other answers, url has to consist of the IP address of computer and not localhost. If that isn't working, before trying anything else, check if the port is correctly mentioned along with IP address when making an api call in the Android app. That is, you should be making an api call to a url which is of the format: http://192.168.X.X:80/api/..

    0 讨论(0)
  • 2021-01-30 05:46

    Additionally, if you want to test on Android/iOS device a PWA Apps developed with Angular, you will need to use:

    ng serve --host 0.0.0.0 to start up the server CLI.

    If you receive "Invalid Host Header", uses:

    ng serve --host 0.0.0.0 --disableHostCheck true

    0 讨论(0)
  • 2021-01-30 05:47

    This worked for me for accessing rails server with IP over local network:

    • The firewall has to be turned off.
    • /etc/hosts should have this entry:

      127.0.0.1 192.168.100.12
      

      where 192.168.100.12 is the ip address which can be found by ifconfig command in terminal.

    • Start rails server with this command:

      rails server -b 0.0.0.0 -p 8080
      

    I was able to access my localhost through http://192.168.100.12:8080/

    0 讨论(0)
  • 2021-01-30 05:51

    Found this great, free tool today - really easy to set up and works like a charm! Versions for Mac OS, Linux and Windows also available.

    https://ngrok.com/

    (am not associated with it in any way)

    0 讨论(0)
提交回复
热议问题