@tinyhttp/ip-filter
v2.1.3
Published
tinyhttp IP filtering middleware
Downloads
214
Maintainers
Readme
@tinyhttp/ip-filter
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 toreq.ip
strict
: throw if invalid IPfilter
: 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)