3.1.0 • Published 10 months ago

@otterhttp/ip-filter v3.1.0

Weekly downloads
-
License
LGPL-3.0-or-later
Repository
github
Last release
10 months ago

@otterhttp/ip-filter

npm (scoped) npm

IP Filtering middleware to send 403 on bad IPs.

Install

pnpm i @otterhttp/ip-filter

API

import { ipFilter } from '@otterhttp/ip-filter'

ipFilter(options)

Returns the IP filter middleware.

Options

  • ip - IP to use. Defaults to req.ip
  • strict: throw if invalid IP
  • filter: blacklist filter (array of strings / RegExps)
  • forbidden: custom 403 message response

Example

import { App } from '@otterhttp/app'
import { ipFilter } from '@otterhttp/ip-filter'

const app = new App()

app.use(ipFilter({ forbidden: 'Get the f*ck out of my server!', filter: [`*.example.com`], strict: true }))

app.get('/', (req, res) => {
  res.send('Hello World!')
})

app.listen(3000)