Heroku nodejs websocket 服务器返回 503? [英] Heroku nodejs websocket server returning 503?
问题描述
这已经解决了,我还不能标记我自己的答案,但已经解决了!
所以我试图在 Heroku 上托管一个 nodejs 服务器,当我在本地托管时该服务器工作正常,问题是每当我尝试使用以下方法进行连接时:
So I'm trying to host a nodejs server on Heroku, the server works fine when I host it local, the problem is that whenever I try to connect using:
const ws = new WebSocket('ws://<myapp>.herokuapp.com');
我在 heroku 日志中收到一个错误:
I get an error in the heroku logs:
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
我不知道如何解决这个问题,我在谷歌上也找不到任何东西.如果有人比我更了解这一点,请告诉我我做错了什么.顺便说一句,这是我的服务器代码:
I have no clue how to fix this, and I can't find anything on google. If someone understands this better then I do, please tell me what I'm doing wrong. Here is my server code btw:
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');
});
推荐答案
我以某种方式修复了它,我只是重新创建了我的应用程序(在 heroku 上)并且它出于某种原因工作,很奇怪但它解决了.
I've fixed it somehow, I simply recreated my application (on heroku) and it worked for some reason, pretty weird but Its solved.
这篇关于Heroku nodejs websocket 服务器返回 503?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!