Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use http2 with Node on Heroku (using Koa)

I have the following code...

const PORT = process.env.PORT || 5000;
const app = new Koa();
...
app.listen(PORT)

This works great both locally and in Heroku. So now I want to use Http2 so I change to the following...

const server = http2.createSecureServer(
    {
        "key": fs.readFileSync('./server-key.pem'),
        "cert": fs.readFileSync('./server-cert.pem')
    }, 
    app.callback()
)
server.listen(PORT);

This works ok locally, however, when I upload to Heroku I get...

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

So how do I get http2 working with Node, Koa, and Heroku?

like image 292
Jackie Avatar asked Oct 14 '25 14:10

Jackie


2 Answers

Per this article on devcenter.heroku.com, Heroku does not yet support http/2.

like image 150
jfriend00 Avatar answered Oct 18 '25 03:10

jfriend00


You can use an add-on like https://elements.heroku.com/addons/expeditedwaf or you can use cloudflare. If you decide to use cloudflare, make sure you add a SSL certificate between cloudflare and heroku.

like image 41
Paulo Abreu Avatar answered Oct 18 '25 02:10

Paulo Abreu