【问题标题】:Heroku + Node + NestJs H13 Error "Connection closed without response"Heroku + Node + NestJs H13 错误“连接关闭且无响应”
【发布时间】:2020-11-08 21:32:17
【问题描述】:

我刚刚花了几个小时让 SSL 在我的免费 heroku 部署上工作。在本地一切正常,我可以GET localhost:3000 并返回"Hello World" 但我的heroku deploy 只返回"Application Error"(使用httphttps):

2020-11-08T21:22:28.066978+00:00 app[web.1]: [32m[Nest] 33   - [39m11/08/2020, 9:22:28 PM   [38;5;3m[NestApplication] [39m[32mNest application successfully started[39m[38;5;3m +7ms[39m

2020-11-08T21:22:28.507341+00:00 heroku[web.1]: State changed from starting to up

2020-11-08T21:22:30.593116+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/" host=<app_name>.herokuapp.com request_id=af5f5b81-2320-4567-9094-79dc17f7d579 fwd="73.243.1.198" dyno=web.1 connect=1ms service=9ms status=503 bytes=0 protocol=https

我的 main.ts 看起来像这样:

async function bootstrap() {
    let app: INestApplication;
    if (process.env.MODE === 'PROD') {
        let httpsOptions = {
            key: process.env.SSL_KEY.replace('"', '').replace("'", ''),
            cert: process.env.SSL_CERT.replace('"', '').replace("'", ''),
        };
        app = await NestFactory.create(AppModule, { httpsOptions });
    } else {
        app = await NestFactory.create(AppModule);
    }

    app.enableCors();
    await app.listen(process.env.PORT);
}
bootstrap().catch(console.error);

我有一个像这样设置的顶级 api

@Controller()
export class AppController {
    constructor() {}

    @Get()
    getBase() {
        return 'Hello World';
    }
}

环境似乎已正确映射。如果PORT 没有被绑定,那么heroku 无论如何都会崩溃。

如果我运行 ping https://&lt;app_name&gt;.herokuapp.com/ 我会得到

ping: cannot resolve https://<app_name>.herokuapp.com/: Unknown host

【问题讨论】:

    标签: node.js heroku


    【解决方案1】:

    不知何故,我不需要 httpsOptions 和我做 SSL 的方式,所以只需 app = await NestFactory.create(AppModule); 就可以了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-05
      • 2017-05-20
      • 2020-04-24
      • 2018-10-14
      • 1970-01-01
      • 2014-11-15
      • 2018-01-11
      • 1970-01-01
      相关资源
      最近更新 更多