-
-
Notifications
You must be signed in to change notification settings - Fork 168
Koa Middleware
Roman edited this page Oct 21, 2018
·
12 revisions
const rateLimiter = new RateLimiterMemory({
points: 5,
duration: 1,
});
app.use(async (ctx, next) => {
try {
await rateLimiter.consume(ctx.ip)
next()
} catch (rejRes) {
ctx.status = 429
ctx.body = 'Too Many Requests'
}
})
Get started
Middlewares and plugins
Migration from other packages
Limiters:
- Valkey Glide
- IoValkey
- Redis
- Memory
- DynamoDB
- Prisma
- Etcd
- MongoDB (with sharding support)
- PostgreSQL
- MySQL
- SQLite
- BurstyRateLimiter
- Cluster
- PM2 Cluster
- Memcached
- RateLimiterUnion
- RateLimiterQueue
Wrappers:
- RLWrapperBlackAndWhite Black and White lists
Knowledge base:
- Block Strategy in memory
- Insurance Strategy
- Comparative benchmarks
- Smooth out traffic peaks
-
Usage example
- Minimal protection against password brute-force
- Login endpoint protection
- Websocket connection prevent flooding
- Dynamic block duration
- Different limits for authorized users
- Different limits for different parts of application
- Block Strategy in memory
- Insurance Strategy
- Third-party API, crawler, bot rate limiting