@tinyhttp/ip-filter
TypeScript icon, indicating that this package has built-in type declarations

2.1.1 • Public • Published

@tinyhttp/ip-filter

npm (scoped) npm

IP Filtering middleware to send 403 on bad IPs.

Install

pnpm i @tinyhttp/ip-filter

API

import { ipFilter } from '@tinyhttp/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 '@tinyhttp/app'
import { ipFilter } from '@tinyhttp/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)

Package Sidebar

Install

npm i @tinyhttp/ip-filter

Weekly Downloads

4

Version

2.1.1

License

MIT

Unpacked Size

6.7 kB

Total Files

7

Last publish

Collaborators

  • dropthebeatbro