koa-request-filter
v1.0.1
Published
request filter middleware for koa 2+
Downloads
6
Maintainers
Readme
koa-request-filter
Install
$ yarn add koa-request-filter
or
$ npm i koa-request-filter
Usage
const Koa = require('koa')
const koaRequestFilter = require('koa-request-filter')
const app = new Koa()
app.use(koaRequestFilter(options))
// full example: https://github.com/neikvon/koa-request-filter/blob/master/example/index.js
Options
methods {array}
: optional- Example:
['GET', 'POST', 'PUT', 'DELETE']
- Example:
include {array}
: optional- Example:
['/api']
- Example:
exclude {array}
: optional- Example:
['/api']
- Example:
error {object}
: optionalstatus {number}
code {string}
rules {object}
: optionalcookies {array}
headers {array}
ip {object}
Options example
methods: ['GET', 'POST', 'PUT', 'DELETE'],
include: [],
exclude: [],
rules: {
cookies: [
{
// string|array
name: 'user',
// function|array|regexp
async include() {
return ['echo']
},
// function|array|regexp
exclude: ['echo1', 'echo2']
}
],
headers: [
{
// string|array
name: 'referer',
// function|array|regexp
include: ['http://www.qq.com'],
// function|array|regexp
exclude: ['http://www.baidu.com']
},
{
name: 'user-agent',
include: /AppleWebKit/g,
exclude: /noexist/g
}
],
// https://www.npmjs.com/package/ip-filter
ip: {
// function|array
include: ['127.*.*.1'],
// function|array
exclude: ['127.1.1.1']
}
},
error: {
status: 403,
code: 'FORBIDDEN_CONTENT'
}