@routup/rate-limit-redis
v3.0.0
Published
Red adapter for the routup rate-limit plugin.
Downloads
18
Maintainers
Readme
@routup/rate-limit-redis
This is a redis adapter for the rate-limit plugin.
Table of Contents
Installation
npm install @routup/rate-limit-redis --save
Documentation
To read the docs, visit https://routup.net
Usage
import { createServer } from 'node:http';
import {
createNodeDispatcher,
Router
} from 'routup';
import { rateLimit } from '@routup/rate-limit';
import { RedisStore } from '@routup/rate-limit-redis';
const router = new Router();
// Apply the rate limiting middleware to API calls only
router.use('/api', rateLimit({
// 15 minutes
windowMs: 15 * 60 * 1000,
// Limit each IP to 100 requests
// per `window` (here, per 15 minutes)
max: 100,
// connection string or ioredis instance
// can be passed optional as argument
store: new RedisStore(),
}));
const server = createServer(createNodeDispatcher(router));
server.listen(3000);
License
Made with 💚
Published under MIT License.
This library is heavily inspired by express-rate-limit-redis.