【发布时间】: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