【问题标题】:Serving Angular App is unreachable on the browser在浏览器上无法访问 Angular App
【发布时间】:2018-01-24 04:01:32
【问题描述】:

我创建了一个简单的 Angular 应用程序,它现在由 npm start(开发模式)在我的 Linux 服务器上提供服务

这里的问题是无法通过浏览器访问。 4200端口也开放了。

该应用程序通过地址http://localhost:4200在本地计算机上完美运行。

现在我尝试通过http://xxx.xx.xx.xx:4200访问服务器上的应用

这是npm start 命令运行时的控制台输出。

> client@0.0.0 start /var/www/html/node1/social2/client
> ng serve

Unable to find "@angular/cli" in devDependencies.

The package "angular-cli" has been deprecated and renamed to "@angular/cli".

Please take the following steps to avoid issues:
"npm uninstall --save angular-cli"

** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Date: 2018-01-23T19:40:09.118Z
Hash: 0698820565e2563b7f26
Time: 16593ms
chunk {inline} inline.bundle.js (inline) 5.79 kB [entry] [rendered]
chunk {main} main.bundle.js (main) 178 kB [initial] [rendered]
chunk {polyfills} polyfills.bundle.js (polyfills) 550 kB [initial] [rendered]
chunk {styles} styles.bundle.js (styles) 33.8 kB [initial] [rendered]
chunk {vendor} vendor.bundle.js (vendor) 9.15 MB [initial] [rendered]

webpack: Compiled successfully.

这可能是什么原因?

【问题讨论】:

标签: javascript angularjs node.js


【解决方案1】:

你需要部署你在本地构建 --prod 后创建的 dist 文件夹,然后通过 index.html 访问应用程序

【讨论】:

    【解决方案2】:

    您提供的主机名和端口无法访问。从您的 Linux 机器外部。

    ng serve 默认值是针对 localhost。

    请改成:

    ng serve --host 0.0.0.0
    

    【讨论】:

    • 我不认为这是最好的做法。您可能需要在此处设置您真正计划使用的 IP 地址
    猜你喜欢
    • 2020-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-06
    • 1970-01-01
    • 1970-01-01
    • 2022-12-04
    • 2015-10-18
    相关资源
    最近更新 更多