如何解决后端开发时使用WebSocket服务部署问题

WebSocket服务使用的为hocuspocus技术,启动WebSocket服务的命令为:

npx @hocuspocus/cli --port 2345 --sqlite

该方式会自动下载依赖包,并进行启动服务。

启动服务的脚本如下:

(base) vm1:~/code/smartdoc_backend_v3/bin$ cat start-websock.sh 
#!/bin/sh

nohup npx @hocuspocus/cli --port 2345 --sqlite > websocks.log 2>&1 &

netstat -anlp | grep 2345

实际部署时,可能会遇到部署失败,主要原因为网络问题。

可以参考下面的步骤进行处理:

  1. 配置代理,保障环境可以访问Google。
  2. 清理环境,设置仓库为
    registry = “https://registry.npmjs.org/”
  3. 在对应的目录中,执行npm的安装
    npm i @hocuspocus/cli
  4. 启动WebSocket服务
  5. 检查服务的启动状态。

具体操作信息如下:

(base) vm1:~/code/smartdoc_backend_v3/bin$ 

(base) vm1:~/code/smartdoc_backend_v3/bin$ npm i @hocuspocus/cli
npm warn deprecated @npmcli/move-file@1.1.2: This functionality has been moved to @npmcli/fs
npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated npmlog@6.0.2: This package is no longer supported.
npm warn deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
npm warn deprecated are-we-there-yet@3.0.1: This package is no longer supported.
npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm warn tarball tarball data for fs-constants@https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz (sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==) seems to be corrupted. Trying again.
npm warn tarball tarball data for tar-stream@https://registry.npmjs.org/tar-stream/-/tar-stream-2.2.0.tgz (sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==) seems to be corrupted. Trying again.
npm warn tarball tarball data for smart-buffer@https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz (sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==) seems to be corrupted. Trying again.
npm warn tarball tarball data for sprintf-js@https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.3.tgz (sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA==) seems to be corrupted. Trying again.
npm warn tarball tarball data for ip-address@https://registry.npmjs.org/ip-address/-/ip-address-9.0.5.tgz (sha512-zHtQzGojZXTwZTHQqra+ETKd4Sn3vgi7uBmlPoXVWZqYvuKmtI0l/VZTjqGmJY9x88GGOaZ9+G9ES8hC4T4X8g==) seems to be corrupted. Trying again.
npm warn deprecated gauge@4.0.4: This package is no longer supported.

added 206 packages in 1m

44 packages are looking for funding
  run `npm fund` for details
(base) vm1:~/code/smartdoc_backend_v3/bin$ ls
init-db.sh  node_modules  package.json  package-lock.json  start-websock.sh  websocks.log
(base) vm1:~/code/smartdoc_backend_v3/bin$ ./start-websock.sh 
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
(base) vm1:~/code/smartdoc_backend_v3/bin$ npm list
bin@ /home/jiaofu/code/smartdoc_backend_v3/bin
└── @hocuspocus/cli@2.13.7

(base) vm1:~/code/smartdoc_backend_v3/bin$ netstat -anlp | grep 2345
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 0.0.0.0:2345            0.0.0.0:*               LISTEN      3111/hocuspocus     
(base) vm1:~/code/smartdoc_backend_v3/bin$ 

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部