Installations
npm install koa-ratelimit-redis
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
8.9.0
NPM Version
5.5.1
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
dillonliang224
Download Statistics
Total Downloads
674
Last Day
1
Last Week
4
Last Month
12
Last Year
73
GitHub Statistics
2 Stars
2 Commits
2 Watching
1 Branches
1 Contributors
Bundle Size
3.96 kB
Minified
1.05 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.1.1
Package Id
koa-ratelimit-redis@0.1.1
Unpacked Size
15.11 kB
Size
3.09 kB
File Count
9
NPM Version
5.5.1
Node Version
8.9.0
Total Downloads
Cumulative downloads
Total Downloads
674
Last day
0%
1
Compared to previous day
Last week
100%
4
Compared to previous week
Last month
33.3%
12
Compared to previous month
Last year
-13.1%
73
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Koa Rate Limit By Redis
Note: This module is based on express-rate-limit.
Install
npm install --save koa-ratelimit-redis
Usage
1const Redis = require('ioredis') 2const RateLimit = require('koa-ratelimit-redis').RateLimit 3const RedisStore = require('koa-ratelimit-redis').RedisStore 4const Koa = require('koa') 5const router = require('koa-router')() 6 7const client = new Redis({ 8 host: '127.0.0.1', 9 port: '6379', 10 db: 0, 11}) 12 13function skip(ctx) { 14 return false 15} 16 17function koaHandler(ctx) { 18 ctx.body = { 19 ok: false, 20 code: 'RATE_LIMIT', 21 msg: 'RATE_LIMIT', 22 } 23} 24 25function defaultRateLimiter(max = 5, expiry = 60, handler = koaHandler) { 26 return new RateLimit({ 27 store: new RedisStore({ 28 client, 29 expiry: expiry, 30 prefix: 'rl:' 31 }), 32 keyGenerator(ctx) { 33 return `default::${ctx.method}:${ctx.path}:${ctx.ip}` 34 }, 35 max: max, 36 statusCode: 200, 37 handler, 38 skip, 39 }) 40} 41 42function doHello(ctx) { 43 ctx.body = 'hello world' 44} 45 46const app = new Koa() 47 48router.get('/hello', defaultRateLimiter(), doHello) 49router.get('/world', defaultRateLimiter(1, 30, (ctx) => { 50 ctx.body = { 51 msg: 'RATE_LIMIT' 52 } 53}), doHello) 54 55app.use(router.middleware()) 56 57app.listen(8080) 58
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
Found 0/2 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
2.6
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More