IP Filtering middleware to send 403 on bad IPs.
pnpm i @tinyhttp/ip-filter
import { ipFilter } from '@tinyhttp/ip-filter'
Returns the IP filter middleware.
-
ip
- IP to use. Defaults toreq.ip
-
strict
: throw if invalid IP -
filter
: blacklist filter (array of strings / RegExps) -
forbidden
: custom 403 message response
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)