Skip to content

Commit d0f8543

Browse files
committed
docs: add example of using an HTTP2, closes #1833
1 parent 056ae99 commit d0f8543

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

docs/guide.md

+21
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- [Response Middleware](#response-middleware)
1616
- [Async operations](#async-operations)
1717
- [Debugging Koa](#debugging-koa)
18+
- [HTTP2](#http2)
1819

1920
## Writing Middleware
2021

@@ -246,3 +247,23 @@ app.use(publicFiles);
246247
```
247248
koa:application use static /public +0ms
248249
```
250+
251+
## HTTP2
252+
253+
Example of setting up an HTTP2 server with Koa using the HTTP compatibility layer:
254+
255+
```js
256+
import Koa from 'koa'
257+
import http2 from 'node:http2'
258+
import fs from 'node:fs'
259+
260+
const app = new Koa();
261+
262+
const onRequestHandler = app.callback();
263+
const serverOptions = {
264+
key: fs.readFileSync('key.pem'),
265+
cert: fs.readFileSync('cert.pem')
266+
}
267+
268+
const server = http2.createSecureServer(serverOptions, onRequestHandler);
269+
```

0 commit comments

Comments
 (0)