|
1 | 1 | # h2 |
2 | 2 |
|
3 | | -[](https://npmjs.com/package/@nuxt/h2) |
4 | | -[](https://npmjs.com/package/@nuxt/h2) |
| 3 | +[](https://npmjs.com/package/@nuxt/h2) |
| 4 | +[](https://npmjs.com/package/@nuxt/h2) |
| 5 | +[](https://bundlephobia.com/result?p=@nuxt/h2) |
5 | 6 |
|
6 | 7 | > h2 is pure and modern JavaScript Server |
7 | 8 |
|
@@ -43,6 +44,27 @@ server.listen(port, () => { |
43 | 44 | }) |
44 | 45 | ``` |
45 | 46 |
|
| 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 | + |
46 | 68 | ## License |
47 | 69 |
|
48 | 70 | MIT |
0 commit comments