# @distributed-systems/http2-server

> a simple http2 server with some basic routing functionality

Latest version **3.2.1** (published 2022-05-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install @distributed-systems/http2-server
pnpm add @distributed-systems/http2-server
yarn add @distributed-systems/http2-server
bun add @distributed-systems/http2-server
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.2.1 |
| Published | 2022-05-19 |
| First published | 2018-09-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 57 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Lina van der Weg |
| Maintainers | ee |

## Links

- npm: https://www.npmjs.com/package/@distributed-systems/http2-server
- npm.io page: https://npm.io/package/@distributed-systems/http2-server

## Dependencies (2)

- [logd](https://npm.io/package/logd.md) ^2.3.1
- [@distributed-systems/http2-lib](https://npm.io/package/@distributed-systems/http2-lib.md) ^3.0.18

## Recent versions

- 3.2.1 (latest) — 2022-05-19
- 3.2.0 — 2022-05-19
- 3.1.0 — 2022-05-17
- 3.0.22 — 2022-05-10
- 3.0.21 — 2022-05-10
- 3.0.20 — 2022-05-10
- 3.0.19 — 2022-05-10
- 3.0.18 — 2022-05-10
- 3.0.17 — 2022-05-10
- 3.0.16 — 2022-05-10
- 3.0.15 — 2022-05-09
- 3.0.14 — 2022-05-04
- 3.0.13 — 2022-04-27
- 3.0.12 — 2022-04-27
- 3.0.11 — 2022-04-22
- … 47 more at https://npm.io/package/@distributed-systems/http2-server/versions

## README

# HTTP2-Server

This server is http2 only. It does not provide upgrades from HTTP 1.1. If you
need to provide HTTP 1.1 in conjunction with HTTP 2 you may use [Envoy Proxy](https://www.envoyproxy.io/)
for translating between the different HTTP Versions. See the examples/envoy 
directory for a simple example involving envoy.


Compatible with node.js 10+, with the `--experimental-modules` flag set.


**ESM**

```javascript
import HTTP2Server from 'es-modules/distributed-systems/http2-server/1.0.0+/index.mjs';
```

**NPM**

```javascript
import HTTP2Server from '@distributed-systems/http2-server';
```


## Function Reference

### HTTP2Server class

The HTTP2Server class provides all functionality to start a HTTP" server. It
emits request events which will pass HTTP2Request class instances to its
listeners.


**Example of a non secure server**

Be aware that no browser is sending non secure requests to a HTTP2 Server, since it's quite insecure.

```javascript
import HTTP2Server from 'es-modules/distributed-systems/http2-server/1.0.0+/index.mjs';

const server = new HTTP2Server({
    port: 8000,
    secure: false,
});


// prepare the server
await server.load();


// intercept request on the GET /status route
const router = server.getRouter();

router.get('/status', (request) => {
    request.response().status(200).send(`I'm very well!`);
});


// start listening. you may also define a port here
await server.listen(8010);

```


#### new HTTP2Server (options)

The constructor takes all options required to start the server. The options are an object containing the configuration parameters.

- key: private key for the server
- certificate: certificate for the server
- port = 443: port to listen on
- router = new Router(): router that handles incoming requests. Defaults to the included Router class
- secure: if set to false, the server starts without requiring clients to use TLS



#### HTTP2Server.registerMiddleware (middleware)

Register a middleware that is executed on each request.

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