【问题标题】:node HTTP-Server is not working properly?节点 HTTP-Server 工作不正常?
【发布时间】:2021-04-08 23:26:49
【问题描述】:

当我在 c: 驱动器中安装 http-server 时,它会自动安装在 d: 驱动器中。

结果如下:-

C:\Users\Kuncham>npm install http-server -g
D:\usr\local\http-server -> D:\usr\local\node_modules\http-server\bin\http-server
D:\usr\local\hs -> D:\usr\local\node_modules\http-server\bin\http-server
+ http-server@0.11.1
updated 1 package in 1.131s

安装后,当我在我的项目文件夹中运行 http-server 时,它将启动 http-server,我们也可以访问命令提示符中给出的链接。浏览器将仅显示未运行我的 Angular 应用程序的文件。

【问题讨论】:

  • 你做过ng build吗?您可能有兴趣(重新)阅读Angular - Deployment
  • 我们正在开发过程中,所以我们只想检查我们的本地系统
  • 什么?您需要构建 Angular 项目以生成浏览器可使用的 HTML 和 Javascript。
  • 所以没有 ng build 就没有办法检查?
  • 许多基于 Angular 的结构在没有先编译成原生 HTML 和 Javascript 的情况下不受浏览器支持。到目前为止,您如何查看/测试您的项目?

标签: angularjs node.js


【解决方案1】:
  1. 使用 npm install -g http-server 命令安装 http-server
  2. 使用 ng build --prod 命令生成构建
  3. 从 cmd 转到 dist/project_name
  4. 在 cmd 上输入 http-server -p 8080
  5. 在浏览器上输入 http://localhost:8080/

【讨论】:

    【解决方案2】:

    对目录执行ng build 并将http-server 指向生成的dist/ 文件夹,其中包含浏览器可以使用的已编译HTML 和Javascript 文件。

    更多信息:Angular - Deployment

    【讨论】:

      【解决方案3】:

      我今天刚刚安装了 http-server,我的问题是当我访问 localhost:8080 时它根本没有提供内容。命令提示符会闪烁一秒钟然后消失。我通过点击http://192.168.40.78:8080 解决了我的问题。 http-server 列出了您可以访问的两个网址。 192 有效,但 localhost 无效。

      【讨论】:

        【解决方案4】:

        运行时指定文件http-server

        http-server [path] [options]
        
        [path] defaults to ./public if the folder exists, and ./ otherwise.
        

        【讨论】:

        • 我确实使用过 http-server ./
        猜你喜欢
        • 2017-11-08
        • 1970-01-01
        • 2013-03-23
        • 1970-01-01
        • 1970-01-01
        • 2015-03-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多