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?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
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)
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
Here's a quick to-do to have your localhost available for tests on other devices :
1) identify the IP of your Android : select the Wi-Fi you're connected (the same as the one the Mac is on), you'll have the IP detailed on it). For the example : we suppose your Android IP is : 192.168.0.10
2) open a Shell on your Mac and edit your host :
3) edit the file as this :
4) Identify your Mac IP : (as @Chuck perfectly explained) (in your shell) :
5) Open your favourite webbrowser you use on your phone and connect to your Mac IP (with the port if needed) with directly something like :
6) Enjoy your test :)
Notice you can do that for every support connected on your Wi-Fi.
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/..
The name "localhost" is just a loopback to your own computer. To access it on your Android, you need to find the computer's IP address.
The most general way of finding this info, which works on both Mac and Linux, is to go into the Terminal and type
ifconfig
. Look for either "en0" or "en1", and under that entry look for the "inet" listing. It will be something along the lines of "192.168.1.100". When you find that address, that's what you'll want to put in your browser's address bar.(On a Mac specifically, you can go to the Sharing pane in System Preferences and it'll tell you there.)
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.