Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/osskit/enforce-client-headers
- Owner: osskit
- License: mit
- Created: 2021-07-18T17:25:43.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-12-15T11:39:21.000Z (about 1 year ago)
- Last Synced: 2024-04-15T01:20:28.070Z (8 months ago)
- Topics: authorization, express, headers, nodejs
- Language: TypeScript
- Homepage:
- Size: 179 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
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']`