具有Express的Heroku Node.js应用-使用“ https”节点模块时,错误代码H13“连接已关闭,无响应”

时间:2019-11-23 04:23:11

标签: node.js express heroku https

我正在制作一个小的Heroku应用程序,该应用程序允许我通过WebSockets发送和接收数据。如标题所示,当我尝试部署该应用程序时,出现了H13错误。

这是heroku logs --tail的输出:

2019-11-23T02:23:27.000000+00:00 app[api]: Build started by user <redacted>
2019-11-23T02:23:41.435926+00:00 app[api]: Release v22 created by user <redacted>
2019-11-23T02:23:41.435926+00:00 app[api]: Deploy deab4a9b by user <redacted>
2019-11-23T02:23:42.746988+00:00 heroku[web.1]: Restarting
2019-11-23T02:23:42.764330+00:00 heroku[web.1]: State changed from up to starting
2019-11-23T02:23:41.000000+00:00 app[api]: Build succeeded
2019-11-23T02:23:43.599900+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2019-11-23T02:23:43.713359+00:00 heroku[web.1]: Process exited with status 143
2019-11-23T02:23:45.771006+00:00 heroku[web.1]: Starting process with command `node index.js`
2019-11-23T02:23:48.533481+00:00 app[web.1]: listening on 27443, path: /app/game
2019-11-23T02:23:50.112376+00:00 heroku[web.1]: State changed from starting to up
2019-11-23T02:23:51.541265+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/" host=<redacted>.herokuapp.com request_id=<redacted> fwd="1.152.
2019-11-23T02:33:24.014895+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/" host=<redacted>.herokuapp.com request_id=<redacted, different from above> fwd="1.152.

这是服务器端代码:

const path = require('path');
const express = require('express');
const app = express();
const https = require('https').createServer(app);
const ws = require('ws');
const server = new ws.Server({ server: https });
const port = process.env.PORT || 8080;

var htmlPath = path.join(__dirname, 'game');
app.use(express.static(htmlPath));

server.on('connection', (socket) => {
    socket.on('message', (msg) => {
        console.log('received ' + msg);
        socket.send('i can hear you!');
    });
});

https.listen(port, () => {
    console.log('listening on ' + port + ", path: " + htmlPath);
});

game目录包含多个文件和子目录,并且该目录的根目录中有一个index.html

以前,我使用的是http节点模块而不是https,并且页面的显示效果还不错。切换到https导致应用崩溃。除了删除http和添加https之外,我没有对以前的版本进行任何更改。

我之所以切换到https的原因是,在使用net::ERR_SSL_PROTOCOL_ERROR模块时,WebSocket连接由于http而失败。

0 个答案:

没有答案