【问题标题】:Using "watch-http-server" for multiple websockets (or alternatives)?对多个 websocket(或替代方案)使用“watch-http-server”?
【发布时间】:2017-09-30 20:20:21
【问题描述】:

我正在使用来自 npm 的 watch-http-server 来启动一个 localhost 服务器,该服务器会在文件更改时自动刷新页面。

https://www.npmjs.com/package/watch-http-server

更具体地说,我将它用于单元测试。 npm 脚本导航到 spec 文件夹并在 localhost 上启动服务器:

"spec": "cd karma_html && cd spec && dir && watch-http-server -a localhost -p 3000 -c-1"

我想对我的主应用程序做同样的事情,但是这个 npm 包中包含的 websocket 似乎没有选项,因此一次只能运行一个。

目前,对于我的主应用程序,我使用常规 http-server 表达式。

https://www.npmjs.com/package/http-server

"start": "cd dist && http-server -a localhost -p 8000 -c-1",

我使用适用于 Windows 的 livereload 应用程序 (http://livereload.com/) 处理页面刷新。但是,这总是在初始化阶段崩溃,因为在短时间内复制了大量文件。这很烦人。

我正在寻找一个支持 websocket 选项的 npm 包或另一个类似于 watch-http-server 的具有不同 websocket 配置的包,以便我可以并行运行它。

【问题讨论】:

    标签: node.js npm websocket server livereload


    【解决方案1】:

    很高兴,我找到了 live-server npm 包,我可以将它用于我的主应用程序。

    https://github.com/tapio/live-server

    安装后,我将我的 npm start 脚本修改为:

    "start": "cd dist && live-server --host=localhost --port=8000",
    

    【讨论】:

      猜你喜欢
      • 2011-05-27
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多