在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:scttcper/koa-simple-ratelimit开源软件地址:https://github.com/scttcper/koa-simple-ratelimit开源编程语言:TypeScript 100.0%开源软件介绍:koa-simple-ratelimitRate limiter middleware for koa v2. Differs from koa-ratelimit by not depending on ratelimiter and using redis ttl (time to live) to handle expiration time remaining. This creates only one entry in redis instead of the three that node-ratelimiter does. Installationnpm install koa-simple-ratelimit Exampleimport Koa from 'koa';
import redis from 'redis';
import { ratelimit } from 'koa-simple-ratelimit';
const app = new Koa();
// Apply rate limit
app.use(ratelimit({
db: redis.createClient(),
duration: 60000,
max: 100
}));
// Response middleware
app.use((ctx, next) => {
ctx.body = 'Stuff!';
return next();
});
app.listen(4000);
console.log('listening on port http://localhost:4000'); Options
ResponsesExample 200 with header fields:
Example 429 response:
LicenseMIT |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论