{"id":18926784,"url":"https://github.com/ladjs/koa-simple-ratelimit","last_synced_at":"2025-10-15T02:06:15.557Z","repository":{"id":65420113,"uuid":"497164139","full_name":"ladjs/koa-simple-ratelimit","owner":"ladjs","description":"Fork of koa-simple-ratelimit with better tests and options","archived":false,"fork":false,"pushed_at":"2022-11-22T04:25:47.000Z","size":155,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-28T04:44:05.798Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ladjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-27T23:30:01.000Z","updated_at":"2022-05-27T23:32:50.000Z","dependencies_parsed_at":"2023-01-22T18:45:13.089Z","dependency_job_id":null,"html_url":"https://github.com/ladjs/koa-simple-ratelimit","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/ladjs/koa-simple-ratelimit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fkoa-simple-ratelimit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fkoa-simple-ratelimit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fkoa-simple-ratelimit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fkoa-simple-ratelimit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ladjs","download_url":"https://codeload.github.com/ladjs/koa-simple-ratelimit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fkoa-simple-ratelimit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279033978,"owners_count":26089402,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-15T02:00:07.814Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T11:17:10.361Z","updated_at":"2025-10-15T02:06:15.511Z","avatar_url":"https://github.com/ladjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [**@ladjs/koa-simple-ratelimit**](https://github.com/ladjs/koa-simple-ratelimit)\n\n[![build status](https://github.com/ladjs/koa-simple-ratelimit/actions/workflows/ci.yml/badge.svg)](https://github.com/ladjs/koa-simple-ratelimit/actions/workflows/ci.yml)\n[![code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)\n[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n[![made with lass](https://img.shields.io/badge/made_with-lass-95CC28.svg)](https://lass.js.org)\n[![license](https://img.shields.io/github/license/ladjs/koa-simple-ratelimit.svg)](LICENSE)\n\n\u003e **Fork of koa-simple-ratelimit with better tests and options.** Rate limiter middleware for koa v2. Differs from [koa-ratelimit](https://github.com/koajs/ratelimit) by not depending on [ratelimiter](https://github.com/tj/node-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.\n\n\n## Table of Contents\n\n* [Install](#install)\n* [Example](#example)\n* [Options](#options)\n* [Responses](#responses)\n* [License](#license)\n\n\n## Install\n\n```sh\nnpm install @ladjs/koa-simple-ratelimit\n```\n\n\n## Example\n\n```js\nconst Koa = require('koa');\nconst Redis = require('ioredis-mock');\n\nconst ratelimit = require('.');\n\nconst app = new Koa();\n\napp.use(\n  ratelimit({\n    db: new Redis(),\n    duration: 60_000,\n    max: 100\n  })\n);\n\napp.use((ctx) =\u003e {\n  ctx.body = 'Stuff!';\n});\n\napp.listen(4000);\n\nconsole.log('listening on port http://localhost:4000');\n\nmodule.exports = app;\n```\n\n\n## Options\n\n* `db` (Object) Redis connection instance **required**\n* `max` (Number) number of max requests within `duration` (defaults to `2500`)\n* `duration` (Number) duration of limit in milliseconds (defaults to `3600000`)\n* `throw` (Boolean) whether or not to throw an error with `ctx.throw` (defaults to `false`)\n* `prefix` (String) redis key prefix (defaults to `limit`)\n* `id` (Function) function accepting an argument `ctx` that returns an id to compare requests with (defaults to `ip` via `ctx.ip`)\n* `allowlist` (Array) an array of ids to allowlist (defaults to `[]`)\n* `blocklist` (Array) an array of ids to blocklist (defaults to `[]`)\n* `logger` (Function) a logger to log database errors with (to prevent app middleware requests from failing due to database connection issues) - set this value to `false` to disable the logger output\n* `headers` (Object) containing keys `remaining`, `reset`, and `total` which set the headers on the HTTP request to `X-RateLimit-Remaining`, `X-RateLimit-Reset`, and `X-RateLimit-Limit` by default respectively\n* `errorMessage` (Function) a function accepting an argument `exp` which is the number of milliseconds until limitation expiry (see code for default) – it also accepts a second argument of `ctx`\n* `ignoredPathGlobs` (Array) defaults to an empty Array, but you can pass an Array of glob paths to ignore\n\n\n## Responses\n\nExample 200 with header fields:\n\n```sh\nHTTP/1.1 200 OK\nX-Powered-By: koa\nX-RateLimit-Limit: 100\nX-RateLimit-Remaining: 99\nX-RateLimit-Reset: 1384377793\nContent-Type: text/plain; charset=utf-8\nContent-Length: 6\nDate: Wed, 13 Nov 2013 21:22:13 GMT\nConnection: keep-alive\n\nStuff!\n```\n\nExample 429 response:\n\n```sh\nHTTP/1.1 429 Too Many Requests\nX-Powered-By: koa\nX-RateLimit-Limit: 100\nX-RateLimit-Remaining: 0\nX-RateLimit-Reset: 1384377716\nContent-Type: text/plain; charset=utf-8\nContent-Length: 39\nRetry-After: 7\nDate: Wed, 13 Nov 2013 21:21:48 GMT\nConnection: keep-alive\n\nRate limit exceeded, retry in 8 seconds\n```\n\n\n## License\n\n[MIT](LICENSE) © Scott Cooper\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fladjs%2Fkoa-simple-ratelimit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fladjs%2Fkoa-simple-ratelimit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fladjs%2Fkoa-simple-ratelimit/lists"}