express-ws route无法连接到heroku

时间:2018-06-10 12:55:36

标签: node.js express heroku websocket

我正在使用express-ws创建一个支持websocket的express.js路由。

这是我的express.js主文件:

const express = require('express');
let expressWs = require('express-ws');
expressWs = expressWs(express());
const app = expressWs.app;
const router = express.Router();

...

const playerRouter = require('./routes/player')(router);

...

module.exports = app;

这是我的路线模块:

module.exports = (router, db) => {
  router.get('/api/player/:id', (req, res, next) => {
    res.send('hello from player route');
    res.end();
  });

  router.ws('/api/player/:id', (ws, req) => {
    ws.on('message', msg => {
      console.log('msg', msg);
    });
  });
}

Localhost:我能够使用websocket调试工具连接到此路由,并且我能够向/ console.log发送消息。

Heroku:我可以通过浏览器浏览到这条路线(成功返回“来自玩家路线的hello”),但是当我尝试使用websocket调试工具进行连接时,我收到以下服务器错误:

  

heroku [router]:at = error code = H13 desc =“Connection without closed without”method = GET path =“/ api / player / 1”host = shielded-river-25076.herokuapp.com request_id = 1ea0d954- 7b06-4f46-b86f-6016cb910be4fwd =“2.229.13.61”dyno = web.1 connect = 0ms service = 1ms status = 503 bytes = 0 protocol = http

0 个答案:

没有答案