代码之家  ›  专栏  ›  技术社区  ›  Alexey Nikonov

托管和部署peerjs服务器

  •  3
  • Alexey Nikonov  · 技术社区  · 7 年前

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

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

    1. 已创建我的新应用程序-> http://mypeerjs.eu-4.evennode.com/
    2. 解包并放入托管源my repository from https://github.com/peers/peerjs-server
    3. 在那个包裹里。json有: “scripts”:{“test”:“mocha test”,“start”:“peerjs--端口9000--键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
    

    在我的本地服务器上已成功部署 我打开了档案,移到 <path_to_peerjs-server>/bin 并使用一行与节点一起运行: node peerjs --port 9000 --key peerjs 我的家庭网络中的服务器成功运行,浏览器对等点相互连接,一切正常。 HERE IS THE LOG FROM LOCAL SERVER 但在主机上,它不是,所以我请求你的帮助。 在日志中,我发现有一个错误

    18: 41:42 102ea39d5429 npm错误!peerjs—端口9000—按键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);
    

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

    3 回复  |  直到 7 年前
        1
  •  13
  •   Tanja skolima    4 年前
    let peer = new Peer({host:'peerjs-server.herokuapp.com', secure:true, port:443})
    

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

        2
  •  1
  •   Shridhar    4 年前

    在应用程序的脚本文件中创建对等方时,请包括以下内容

    const peer = new Peer({
         path: '/peerjs',
         host: '/',
         port: '443'
    })
    
        3
  •  0
  •   WHY    3 年前

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

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