最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Change localhost:4200 to something mysite:4200 in Angular 5 - Stack Overflow

programmeradmin3浏览0评论

I want to change host name for testing purpose. I have tried ng serve --host 0.0.0.0 but app again runs on localhost:4200. Is there a way that app runs on different host name (word) in browser?

I want to change host name for testing purpose. I have tried ng serve --host 0.0.0.0 but app again runs on localhost:4200. Is there a way that app runs on different host name (word) in browser?

Share Improve this question asked Feb 19, 2018 at 18:27 Umair JameelUmair Jameel 1,6733 gold badges31 silver badges58 bronze badges 3
  • I mean, wrote something else here, I wrote the actual port actual port. But I want to word to be shown. – Umair Jameel Commented Feb 19, 2018 at 18:31
  • It has to be localhost though as the launch point, it is running on your PC and that address will always point back to your PC. That is not configurable, only the port number is. – Igor Commented Feb 19, 2018 at 18:33
  • 1 @lgor - 0.0.0.0 is legal for the --host parameter for ng serve. It's simply telling ng how to bind. Using 0.0.0.0 is basically telling ng that it can accept requests from any IP address. The default binding is 127.0.0.1 and thus only requests from the local machine will work - but it actually doesn't matter the hostname (localhost or a custom one). – Randy Commented Feb 19, 2018 at 18:41
Add a ment  | 

2 Answers 2

Reset to default 7

If you're on Mac or Linux and just for local testing, you can edit /etc/hosts and add your own dns mapping. I'm sure you can do something similar on Windows.

For example you can add adding mysite to your hosts file:

127.0.0.1       mysite

Then you can access your app by going to http://mysite:4200.

Note that if making changes to your hosts file don't appear to work you may need to either reboot or make your OS reload your hosts file. See the bottom of this page for more information: https://www.imore./how-edit-your-macs-hosts-file-and-why-you-would-want

  1. Add the next row to the end of your hosts file: 127.0.0.1 my.local.host
  2. Start app: ng serve --host "my.local.host"
发布评论

评论列表(0)

  1. 暂无评论