Conclusion. If you're working on a computer with an active internet connection, you can now set up access to your localhost from anywhere in only a few minutes!
You need to do a number of things: Ensure that you can reach the site from another computer on the LAN. Configure the computer running Tomcat to have a fixed IP address on your LAN. Forward the required port(s) from your router to the fixed IP of the Tomcat server.
If you can access a server running on your own machine via 127.0. 0.1 (or localhost ) but not via the computer's ip address, this means that the server software is configured to listen on the localhost interface only.
Using ng serve --host 0.0.0.0
will allow you to connect to the ng serve
using your ip instead of localhost
.
EDIT
In newer versions of the cli, you have to provide your local ip address instead
EDIT 2
In newer versions of the cli (I think v5 and up) you can use 0.0.0.0
as the ip again to host it for anyone on your network to talk to.
As a side note Make sure your connection is set to Public in your OS settings.
Mac users:
ng serve --host 192.168.1.x
Then you must be able to see your page on other devices through 192.168.1.x:4200
.
run command
ng serve --host=0.0.0.0 --disable-host-check
this will disable host check and allow to access from outside(instead of localhost) with IP address
You can use the following command to access with your ip.
ng serve --host 0.0.0.0 --disable-host-check
If you are using npm and want to avoid running the command every time, we can add the following line to the package.json file in the scripts section.
"scripts": {
...
"start": "ng serve --host 0.0.0.0 --disable-host-check"
...
}
Then you can run you app using the below command to be accessed from the other system in the same network.
npm start
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With