All Projects → scttcper → koa-simple-ratelimit

scttcper / koa-simple-ratelimit

Licence: MIT license
Simple rate limiter for Koa.js v2 web framework

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to koa-simple-ratelimit

Blog Service
blog service @nestjs
Stars: ✭ 188 (+1005.88%)
Mutual labels:  koa, koa2
koa2-swagger-ui
Swagger UI as Koa v2 middleware
Stars: ✭ 95 (+458.82%)
Mutual labels:  koa, koa2
Cool Admin Api
cool-admin-api 是基于egg.js、typeorm、jwt等封装的api开发脚手架、快速开发api接口
Stars: ✭ 188 (+1005.88%)
Mutual labels:  koa, koa2
Vue Webpack Config
Koa2、Webpack、Vue、React、Node
Stars: ✭ 151 (+788.24%)
Mutual labels:  koa, koa2
nodejs-koa-blog
基于 Node.js Koa2 实战开发的一套完整的博客项目网站
Stars: ✭ 1,611 (+9376.47%)
Mutual labels:  koa, koa2
Koa Hbs
Handlebars templates for Koa.js
Stars: ✭ 156 (+817.65%)
Mutual labels:  koa, koa2
Koa Webpack Middleware
webpack dev&hot middleware for koa2
Stars: ✭ 215 (+1164.71%)
Mutual labels:  koa, koa2
Postgraphile
GraphQL is a new way of communicating with your server. It eliminates the problems of over- and under-fetching, incorporates strong data types, has built-in introspection, documentation and deprecation capabilities, and is implemented in many programming languages. This all leads to gloriously low-latency user experiences, better developer experiences, and much increased productivity. Because of all this, GraphQL is typically used as a replacement for (or companion to) RESTful API services.
Stars: ✭ 10,967 (+64411.76%)
Mutual labels:  koa, koa2
koa-xml-body
koa middleware to parse xml request body
Stars: ✭ 36 (+111.76%)
Mutual labels:  koa, koa2
koa-mongoDB
😊😊Koa and mongoose build services
Stars: ✭ 24 (+41.18%)
Mutual labels:  koa, koa2
Sactive Web
🚀 A dependency injection web framework for Node.js.
Stars: ✭ 143 (+741.18%)
Mutual labels:  koa, koa2
node-typescript-starter
REST API using Node with typescript, KOA framework. TypeORM for SQL. Middlewares JWT (auth), CORS, Winston Logger, Error, Response
Stars: ✭ 19 (+11.76%)
Mutual labels:  koa, koa2
Koa Proxies
a [email protected] proxy middleware
Stars: ✭ 125 (+635.29%)
Mutual labels:  koa, koa2
Github Ranking
🔍GitHub不同语言热门项目排行,Vue.js做页面展示
Stars: ✭ 160 (+841.18%)
Mutual labels:  koa, koa2
Koalerplate
Simple Koa Boilerplate for APIs
Stars: ✭ 118 (+594.12%)
Mutual labels:  koa, koa2
Egg Core
A core Pluggable framework based on koa.
Stars: ✭ 194 (+1041.18%)
Mutual labels:  koa, koa2
Chatroom
vue2聊天室,图灵机器人,node爬虫
Stars: ✭ 103 (+505.88%)
Mutual labels:  koa, koa2
Strapi
🚀 Open source Node.js Headless CMS to easily build customisable APIs
Stars: ✭ 41,786 (+245700%)
Mutual labels:  koa, koa2
Strapi Sdk Javascript
🔌 Official JavaScript SDK for APIs built with Strapi.
Stars: ✭ 247 (+1352.94%)
Mutual labels:  koa, koa2
koahub-cli
KoaHub CLI -- KoaHub.js的开发工具,自动babel编译 ES6/7(Generator Function, Class, Async & Await)并且文件修改后自动重启。
Stars: ✭ 16 (-5.88%)
Mutual labels:  koa, koa2

koa-simple-ratelimit

NPM version build status coverage

Rate 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.

Installation

npm install koa-simple-ratelimit

Example

import 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

  • db redis connection instance
  • max max requests within duration [2500]
  • duration of limit in milliseconds [3600000]
  • id id to compare requests [ip]
  • allowlist array of ids to allowlist
  • blocklist array of ids to blocklist
  • prefix redis key prefix ["limit"]

Responses

Example 200 with header fields:

HTTP/1.1 200 OK
X-Powered-By: koa
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 99
X-RateLimit-Reset: 1384377793
Content-Type: text/plain; charset=utf-8
Content-Length: 6
Date: Wed, 13 Nov 2013 21:22:13 GMT
Connection: keep-alive

Stuff!

Example 429 response:

HTTP/1.1 429 Too Many Requests
X-Powered-By: koa
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1384377716
Content-Type: text/plain; charset=utf-8
Content-Length: 39
Retry-After: 7
Date: Wed, 13 Nov 2013 21:21:48 GMT
Connection: keep-alive

Rate limit exceeded, retry in 8 seconds

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].