Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/osskit/enforce-client-headers

Client headers validation middleware
https://github.com/osskit/enforce-client-headers

authorization express headers nodejs

Last synced: 9 days ago
JSON representation

Client headers validation middleware

Awesome Lists containing this project

README

        





# enforce-client-headers
Enforce headers against http calls to your Express API

## Install
```
yarn add @osskit/enforce-client-headers
```

## Usages

### Simple
```
import { enforceClientHeaders } from '@osskit/enforce-client-headers'

const server = express();
const socketServer = io();

server.use(enforceClientHeaders());
socketServer.use(enforceClientHeaders());
```

### Add more headers

```
import { enforceClientHeaders, defaultHeaders } from '@osskit/enforce-client-headers'

const server = express();
const socketServer = io();

const headers = [...defaultHeaders, 'my-extra-header'];

server.use(enforceClientHeaders({ headers });
socketServer.use(enforceClientHeaders, { headers });
```

## API

### enforceClientHeaders({headers})
#### headers
Type: `string[]`

The headers you want to enforce on the request

Throws a `400 - missing ${header}` error upon missing required header

### defaultHeaders

Type: `string[]`, by default `['x-api-client', 'x-api-client-version']`