# http2-hooks

> Helper functions for making an http2 server.

Latest version **1.0.0** (published 2021-01-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install http2-hooks
pnpm add http2-hooks
yarn add http2-hooks
bun add http2-hooks
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2021-01-03 |
| First published | 2021-01-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 28.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Dima Doronin |
| Maintainers | ddoronin |
| Keywords | http2, hooks |

## Links

- npm: https://www.npmjs.com/package/http2-hooks
- Repository: https://github.com/ddoronin/http2-hooks
- Homepage: https://github.com/ddoronin/http2-hooks#readme
- Issues: https://github.com/ddoronin/http2-hooks/issues
- npm.io page: https://npm.io/package/http2-hooks

## Dependencies (3)

- [mime-types](https://npm.io/package/mime-types.md) ^2.1.27
- [path-to-regexp](https://npm.io/package/path-to-regexp.md) ^6.2.0
- [@types/mime-types](https://npm.io/package/@types/mime-types.md) ^2.1.0

## Recent versions

- 1.0.0 (latest) — 2021-01-03

## README

# http2-hooks
```
yarn add http2-hooks
```

Build an HTTP/2 server is simple as this:
``` typescript
import http2 from 'http2';
import path from 'path';
import fs from 'fs';
import mime from 'mime-types';
import { useHttp2Server, ConsoleMiddlewareHttp2Hook, RouterHttp2Hook, RouterFactory } from 'http2-hooks';

const server = http2.createSecureServer({...});
useHttp2Server(server, [
    new ConsoleMiddlewareHttp2Hook(),
    new RouterHttp2Hook(
        new RouterFactory().get("/:static*", (stream, headers) => {
            const staticPath = path.resolve(__dirname, './static');
            const fullPath = path.join(staticPath, headers[':path'] as string);
            fs.createReadStream(fullPath).pipe(stream).respond({ 'content-type': mime.lookup(fullPath) as string });
        }))
]).listen(443);
```

---
_Source: https://npm.io/package/http2-hooks · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
