Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/saka7/fastify-block-list
IP-s blockings plugin for fastify
https://github.com/saka7/fastify-block-list
blocklist fastify fastify-plugin whitelist
Last synced: about 2 months ago
JSON representation
IP-s blockings plugin for fastify
- Host: GitHub
- URL: https://github.com/saka7/fastify-block-list
- Owner: Saka7
- License: mit
- Created: 2020-08-31T10:29:43.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-08-31T18:16:42.000Z (over 4 years ago)
- Last Synced: 2024-11-16T16:09:13.321Z (about 2 months ago)
- Topics: blocklist, fastify, fastify-plugin, whitelist
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/fastify-block-list
- Size: 77.1 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fastify-block-list
IP-s blocklisting plugin for fastify
## Install
```bash
npm i fastify-block-list
```## Usage
Simply require this plugin, and set the array of ip addresses to block
```javascript
const fastify = require('fastify')()
const fastifyBlocklist = require('fastify-block-list')fastify.register(fastifyBlocklist, {
blocklist: ['127.0.0.1'],
})fastify.get('/', (req, res) => {
res.send({ ok: true })
})fastify.listen(3000, (err, address) => {
if (err) throw err
console.log(`Sever is listening on address: ${address}`)
})
```You can also specify custom error response
```javascript
fastify.register(fastifyBlocklist, {
blocklist: ['127.0.0.1'],
error: {
code: 400,
body: 'Custom message',
}
})
```Or provide custom error handler function
```javascript
fastify.register(fastifyBlocklist, {
blocklist: ['127.0.0.1'],
error: {
handler: async (req, reply) => {
reply.code(403).send({error: 'Custom error'})
}
}
})
```Regular expressions are also supported
```javascript
fastify.register(fastifyBlocklist, {
blocklist: [/^192\.168\.\d{1-3}\.\d{1-3}$/],
})
```## License
MIT