托管和部署 peerjs 服务器

Hosting and deploy peerjs server

帮助我使用 webRTC 库 'peer.js'。为了让它工作,我需要一个我自己的服务器,所以我尝试在 evennode.com 上安装 peerjs。在托管设置中声明启动命令 -> 自动检测(推荐)(如果 package.json 可用,您的应用程序将使用 npm start 启动。)。

所以我做了接下来的动作:

  1. 创建了我的新应用程序-> http://mypeerjs.eu-4.evennode.com/
  2. https://github.com/peers/peerjs-server
  3. 解压并放入我的存储库的托管源
  4. 在那个包中 .json 有: "scripts": { "test": "mocha test", "start": "peerjs --port 9000 --key peerjs" } 我也尝试声明(因为我 运行 它来自我的本地服务器)

    "start": "bin/peerjs --port ${PORT:=9000}"

问题:应用程序不 start.The 记录下一个写入:

2018-01-27 18:41:41 102ea39d5429 ---> Starting app
2018-01-27 18:41:41 102ea39d5429 Detected package.json start script
2018-01-27 18:41:42 102ea39d5429 
2018-01-27 18:41:42 102ea39d5429 > peer@0.2.8 start /data/app
2018-01-27 18:41:42 102ea39d5429 > peerjs --port 9000 --key peerjs
2018-01-27 18:41:42 102ea39d5429 
2018-01-27 18:41:42 102ea39d5429 sh: 1: peerjs: not found
2018-01-27 18:41:42 102ea39d5429 npm ERR! peer@0.2.8 start: `peerjs --port 9000 --key peerjs`
2018-01-27 18:41:42 102ea39d5429 npm ERR! `sh "-c" "peerjs --port 9000 --key peerjs"` failed with 127
2018-01-27 18:41:42 102ea39d5429 npm ERR! 
2018-01-27 18:41:42 102ea39d5429 npm ERR! Failed at the peer@0.2.8 start script.
2018-01-27 18:41:42 102ea39d5429 npm ERR! This is most likely a problem with the peer package,
2018-01-27 18:41:42 102ea39d5429 npm ERR! not with npm itself.
2018-01-27 18:41:42 102ea39d5429 npm ERR! Tell the author that this fails on your system:
2018-01-27 18:41:42 102ea39d5429 npm ERR!     peerjs --port 9000 --key peerjs
2018-01-27 18:41:42 102ea39d5429 npm ERR! You can get their info via:
2018-01-27 18:41:42 102ea39d5429 npm ERR!     npm owner ls peer
2018-01-27 18:41:42 102ea39d5429 npm ERR! There is likely additional logging output above.
2018-01-27 18:41:42 102ea39d5429 
2018-01-27 18:41:42 102ea39d5429 npm ERR! System Linux 3.10.0-693.5.2.el7.x86_64
2018-01-27 18:41:42 102ea39d5429 npm ERR! command "/data/n/bin/node" "/data/n/bin/npm" "start"
2018-01-27 18:41:42 102ea39d5429 npm ERR! cwd /data/app
2018-01-27 18:41:42 102ea39d5429 npm ERR! node -v v0.9.1
2018-01-27 18:41:42 102ea39d5429 npm ERR! npm -v 1.1.59
2018-01-27 18:41:42 102ea39d5429 npm ERR! code ELIFECYCLE
2018-01-27 18:41:42 102ea39d5429 npm ERR! 
2018-01-27 18:41:42 102ea39d5429 npm ERR! Additional logging details can be found in:
2018-01-27 18:41:42 102ea39d5429 npm ERR!     /data/app/npm-debug.log
2018-01-27 18:41:42 102ea39d5429 npm ERR! not ok code 0

在我的本地服务器上部署成功 我解压缩存档,移动到 <path_to_peerjs-server>/bin 并使用一行 运行 它与节点: node peerjs --port 9000 --key peerjs 我的家庭网络中的服务器成功 运行,浏览器对等点相互连接并且一切正常。 HERE IS THE LOG FROM LOCAL SERVER 但在托管上它没有,所以我请求你的帮助。 在日志中,正如我所得到的,有一个错误

18:41:42 102ea39d5429 npm ERR! peerjs --port 9000 --key peerjs

感谢提前!

编辑 我已将应用程序上传到我的托管服务器:

var http = require('http');
var server = http.createServer(function(req, res) {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello world!');
});
server.listen(process.env.PORT);

它有效,你可能会看到它。 我觉得问题出在侦听器端口打开

let peer = new Peer({host:'peerjs-server.herokuapp.com', secure:true, port:443})

而不是托管您自己的对等服务器

当您在脚本文件中为您的应用程序创建对等点时,请包含此内容

const peer = new Peer({
     path: '/peerjs',
     host: '/',
     port: '443'
})

如果不需要也可以删除端口。我的服务器配置如下

const myPeer = new Peer({host: 'peerjs-server.herokuapp.com', secure: true, path: '/peerapp'})