【发布时间】:2020-11-08 21:32:17
【问题描述】:
我刚刚花了几个小时让 SSL 在我的免费 heroku 部署上工作。在本地一切正常,我可以GET localhost:3000 并返回"Hello World" 但我的heroku deploy 只返回"Application Error"(使用http 或https):
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://<app_name>.herokuapp.com/ 我会得到
ping: cannot resolve https://<app_name>.herokuapp.com/: Unknown host
【问题讨论】: