【问题标题】:Heroku nodejs websocket server returning 503?Heroku nodejs websocket服务器返回503?
【发布时间】:2017-12-31 13:47:12
【问题描述】:

已解决,我还不能标记自己的答案,但已解决!

所以我试图在 Heroku 上托管一个 nodejs 服务器,当我在本地托管它时服务器工作正常,问题是每当我尝试使用连接时:

const ws = new WebSocket('ws://<myapp>.herokuapp.com');

heroku 日志中出现错误:

heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=<myapp>.herokuapp.com request_id=<request-id> fwd="<my-ip>" dyno= connect= service= status=503 bytes= protocol=http

我不知道如何解决这个问题,我在谷歌上也找不到任何东西。如果有人比我更了解这一点,请告诉我我做错了什么。 这是我的服务器代码顺便说一句:

const WebSocket = require('ws');

var PORT = process.env.PORT || 3000;

const wss = new WebSocket.Server({ port: PORT });

console.log("Listening on %d", PORT);

wss.on('connection', function connection(ws) {
  ws.on('message', function incoming(message) {
  console.log('received: %s', message);
});

ws.send('something');
});

【问题讨论】:

  • 另外,process.env.PORT | 3000 应该是 process.env.PORT || 3000
  • @RobertMoskal 我试过了,得到了`!找不到该功能。`
  • @robertklep 我也试过了,但没有什么不同,因为它仍然记录了这个:app[worker.1]: Listening on 28040

标签: node.js heroku websocket server


【解决方案1】:

我已经以某种方式修复了它, 我只是重新创建了我的应用程序(在 heroku 上),它出于某种原因工作,很奇怪,但它解决了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-25
    • 2014-04-07
    • 2021-04-01
    • 2012-08-15
    • 2014-12-12
    • 2014-09-08
    • 2020-05-26
    • 1970-01-01
    相关资源
    最近更新 更多