Skip to content

Commit 36ce7c9

Browse files
committed
chore: improve docs and add bad
1 parent 9aec69e commit 36ce7c9

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# h2
22

3-
[![npm](https://img.shields.io/npm/dm/@nuxt/h2.svg?style=flat-square)](https://npmjs.com/package/@nuxt/h2)
4-
[![npm (scoped with tag)](https://img.shields.io/npm/v/@nuxt/h2/latest.svg?style=flat-square)](https://npmjs.com/package/@nuxt/h2)
3+
[![d](https://img.shields.io/npm/dm/@nuxt/h2.svg?style=flat-square)](https://npmjs.com/package/@nuxt/h2)
4+
[![v](https://img.shields.io/npm/v/@nuxt/h2/latest.svg?style=flat-square)](https://npmjs.com/package/@nuxt/h2)
5+
[![b](https://img.shields.io/bundlephobia/min/@nuxt/h2/latest.svg?style=flat-square)](https://bundlephobia.com/result?p=@nuxt/h2)
56

67
> h2 is pure and modern JavaScript Server
78
@@ -43,6 +44,27 @@ server.listen(port, () => {
4344
})
4445
```
4546

47+
## Technical
48+
49+
There are two vital parts that make it working: Stack Runner (`App`), and `promisifyHandle`.
50+
51+
### App
52+
53+
App is basically a http server handle with `req, res` and attached utilities that runs stack
54+
of middleware/handles in parallel. It will stop iteration in case of `writableEnded` flag is set on response
55+
(which means `res.end` called) and throw 404 if `writableEnded` flag is not set at the end.
56+
57+
Additionally app, has a quick prefix matcher and will automatically call `res.end` in case of any stack layers returning a value.
58+
59+
### `promisifyHandle`
60+
61+
Converts a classic middleware (`req, res, next?`) into promisifier version ready to use with App
62+
63+
- If middleware has 3rd next/callback param, promise will `resolve/reject` when being called
64+
- If middleware returns a promise, it will be **chained** to main promise
65+
- If calling middleware throws an immediate error, promise will be rejected
66+
- On `close` and `close` events of res, promise will `resolve/reject` (to ensure if middleware simply calls `res.end`)
67+
4668
## License
4769

4870
MIT

0 commit comments

Comments
 (0)