![](/img/trans.png)
[英]How do I get the client's IP address in Node.js when using the HTTP2 module?
[英]How do I use http2 with Node on Heroku (using Koa)
我有以下代碼...
const PORT = process.env.PORT || 5000;
const app = new Koa();
...
app.listen(PORT)
這在本地和 Heroku 都非常有效。 所以現在我想使用Http2所以我改為以下......
const server = http2.createSecureServer(
{
"key": fs.readFileSync('./server-key.pem'),
"cert": fs.readFileSync('./server-cert.pem')
},
app.callback()
)
server.listen(PORT);
這在本地工作正常,但是,當我上傳到 Heroku 時,我得到......
2021-06-24T00:43:00.383108+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/" host=my-app.herokuapp.com request_id=604f4a2c-8dd2-4cfa-9cf2-3cce5ef76070 fwd="..." dyno=web.1 connect=0ms service=1ms status=503 bytes=0 protocol=https
那么如何讓 http2 與 Node、Koa 和 Heroku 一起工作呢?
根據 devcenter.heroku.com 上的這篇文章,Heroku 尚不支持 http/2。
您可以使用https://elements.heroku.com/addons/expeditedwaf之類的附加組件,也可以使用 cloudflare。 如果您決定使用 cloudflare,請確保在 cloudflare 和 heroku 之間添加 SSL 證書。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.