Localhost running on mac.. Can I view it on my And

2020-05-11 21:28发布

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?

10条回答
别忘想泡老子
2楼-- · 2020-05-11 21:58

Chunk's answer is correct, assuming your mobile device and your computer are on the same network. However, if you want your localhost server to be visible to the wider Internet (e.g. for testing over 3G, developing webhooks or collaboration with a remote colleague/client), more is needed as local addresses (starting with 10.* or 192.168.*) are not visible to the wider Internet.

The traditional solution to that is port forwarding and dynamic DNS, but lately a few services have popped up which aim to make this process simpler (disclaimer: I am the author of one of them, PageKite).

These services provide you with a public DNS name and software which connect your "localhost" with an in-the-cloud relay server (a.k.a. a reverse proxy). For example, if you are using PageKite, you can run the following command in the terminal:

$ pagekite.py 80 yourname.pagekite.me

... to create a mapping from http://yourname.pagekite.me/ to the web server running on http://localhost:80. While the program is running, your localhost site will be visible to the rest of the Internet. In order to make it private again, you simply turn off the pagekite.py connector program.

For completeness, here are some of the localhost tunneling services I am aware of:

  • PageKite is Free Software (Python) with a "pay-what-you-want" on-line service. You can create as many long-lived subdomains as you want, a wild-card SSL certificate is included and front-end relays run in multiple geographic locations to provide redundancy and responsiveness.
  • Localtunnel is a free-of-charge (sponsored by Twilio) Ruby solution which gives connections temporary names. Note that names are recycled so you may see unexpected traffic while the connection is live.
  • Showoff.io and Tunnlr.com are proprietary paid service comparable to Localtunnel, based on the same basic technology (ssh tunnels).

(Sorry about not linking to the last two, SO spam protection is preventing me from being fair to my competitors. ;-)

查看更多
男人必须洒脱
3楼-- · 2020-05-11 21:59

Although one answer has been accepted but this worked for me:

  1. Make sure both your computer and android device are on same network.
  2. get your computer's ip address. (in case of mac type ifconfig inside terminal and look for en0/en1 -> inet it should be something like 19*.16*.1.4.)
  3. Open your mobile settings and go to network-> long press your wifi network-> modify network -> scroll down to advanced options -> chose proxy manual and in proxy hostname type your address i.e. 19*.16*.1.4 inside port enter your port. and save it.

  4. search for what is my ip in google chrome, and get your ip, lets say it is 1**.1**.15*.2**

  5. try accessing 1**.1**.15*.2**:port/ from your mobile device.

It is as simple as this.

查看更多
我欲成王,谁敢阻挡
4楼-- · 2020-05-11 22:03

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/

查看更多
▲ chillily
5楼-- · 2020-05-11 22:05

MacOS Catalina 10.15.4

  1. Go to Settings -> Security and Privacy.

enter image description here

  1. Select Firewall tab and unlock the settings using your laptop password:

enter image description here

  1. Select Firewall Options... and in the dialog uncheck the box for Block all incoming connections and hit OK.

enter image description here

  1. Open Terminal and type ifconfig. Look for the en0. In the section find the address sitting near inet - this is the address of your laptop in a local network.
en0: flags0=<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 0
...
        inet 192.168.0.123 netmask 0xffffff00 broadcast 192.168.0.255
...

  1. Use the IP address + the port (in case you are using localhost:4200 for development), otherwise omit the port:
http://<IP address found in en0 -> inet>:<port if needed>
  1. Profit!
查看更多
登录 后发表回答