如何在我的Windows桌面上运行localhost的移动设备上运行我的Angular站点

H. *_*lyn 36 networking webserver android localhost angular-cli

我知道从这个问题和在桌面上的localhost上运行的 超级用户站点上的答案在Android设备上无法访问(PS:这个问题在链接中的问题上继续)该命令ng serve打开一个错误配置的Web服务器.

问题是如何在不部署我的网站的情况下在Android设备上运行我的网站.我将尝试http://192.168.0.168:4200使用Angular-CLI 在此URL上运行该站点.

Ahm*_*lam 70

试试服务--host选项,如本期所述:https://github.com/angular/angular-cli/issues/1793 intellix评论.

  1. ng serve --host 0.0.0.0
  2. 按照查找当地的IP地址,
  3. <local ip adress>:4200从同一网络上的任何设备导航到.

否则请尝试https://ngrok.com/从本地网络打开隧道到您的计算机localhost.基本上,您的计算机会将4200端口转发到网络上任何设备都可以访问的外部IP和端口.

  • 如果 url 在您的移动设备上仍然不可用,请尝试禁用防火墙 (5认同)

Sha*_*got 15

  1. 首先验证您的机器IP地址.

    • 在Windows上,键入ipconfig提示(复制IPv4).
    • 在Mac上,键入ifconfig |grep inet终端(复制inet).


    就我而言,这是192.168.0.10.

  2. 接下来,输入ng serve --host 192.168.0.10.

  3. 好的,您的应用程序在同一网络上的所有设备上播出.

  4. 现在只会http://192.168.0.10:4200/工作,localhost而不是更多.


小智 8

当我尝试使用

ng serve --host local ip address

我正面临

无效的标头请求

此问题已解决使用 --disable-host-check

ng serve --host local ip address --disable-host-check