托管和部署 peerjs 服务器

Ale*_*nov 2 hosting node.js webrtc 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. 在那个包 .json 中有: "scripts": { "test": "mocha test", "start": "peerjs --port 9000 --key peerjs" } 我也试图说明(因为我从我的本地服务器)

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

问题:应用程序没有启动。日志接下来写道:

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
Run Code Online (Sandbox Code Playgroud)

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

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);
Run Code Online (Sandbox Code Playgroud)

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

小智 12

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

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