Skip to content

Commit

Permalink
docs: add example of using an HTTP2, closes #1833
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanong committed Aug 31, 2024
1 parent 056ae99 commit d0f8543
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- [Response Middleware](#response-middleware)
- [Async operations](#async-operations)
- [Debugging Koa](#debugging-koa)
- [HTTP2](#http2)

## Writing Middleware

Expand Down Expand Up @@ -246,3 +247,23 @@ app.use(publicFiles);
```
koa:application use static /public +0ms
```

## HTTP2

Example of setting up an HTTP2 server with Koa using the HTTP compatibility layer:

```js
import Koa from 'koa'
import http2 from 'node:http2'
import fs from 'node:fs'

const app = new Koa();

const onRequestHandler = app.callback();
const serverOptions = {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
}

const server = http2.createSecureServer(serverOptions, onRequestHandler);
```

0 comments on commit d0f8543

Please sign in to comment.