@juntoz/koa-require-header
Version:
Koa middleware to require an http header and write to state variable
27 lines (20 loc) • 846 B
Markdown
This package contains a middleware that will require an http header to be present on the request, and if present, it will write the value into a state variable.
To install the package
```
npm install @juntoz/koa-require-header
```
To use it
```
const koaRequireHeader = require('@juntoz/koa-require-header');
var koaApp = new Koa();
koaApp.use(koaRequireHeader({ /*options*/ }));
```
Where options is an object that can contain the following fields
```
{
headerName: null, // header name that should come in the request to validate and match
stateName: null, // optional ctx.state property name when the header is found. If null, the headerName is converted to camelCase.
ifNotFound: 'throw' // set what to do if the header is not found. Possible values ['throw', 'ignore'].
}
```