Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/osskit/fastify-enforce-headers
Enforce headers to your Fastify API calls
https://github.com/osskit/fastify-enforce-headers
authorization fastify fastify-plugin headers nodejs
Last synced: 27 days ago
JSON representation
Enforce headers to your Fastify API calls
- Host: GitHub
- URL: https://github.com/osskit/fastify-enforce-headers
- Owner: osskit
- License: mit
- Created: 2022-06-18T16:31:39.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-16T11:21:29.000Z (3 months ago)
- Last Synced: 2024-10-18T03:13:37.852Z (3 months ago)
- Topics: authorization, fastify, fastify-plugin, headers, nodejs
- Language: TypeScript
- Homepage:
- Size: 219 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# fastify-enforce-headers
Enforce headers against http calls to your fastify API
## Install
```
yarn add @osskit/fastify-enforce-headers
```## Usages
### Simple
```
import fastify from 'fastify';
import { enforceHeaders } from '@osskit/fastify-enforce-headers';await fastify.register(enforceHeaders);
```### Extra headers
```
import fastify from 'fastify';
import { enforceHeaders, defaultHeaders } from '@osskit/fastify-enforce-headers';await fastify.register(enforceHeaders, { headers: [...defaultHeaders, 'x-custom-header'] });
```## API
### enforceHeaders({headers})
#### headers
Type: `string[]`
Default: `[]`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']`