{"id":13800405,"url":"https://github.com/nswbmw/koa-ip","last_synced_at":"2025-05-13T09:31:35.968Z","repository":{"id":19472310,"uuid":"22717583","full_name":"nswbmw/koa-ip","owner":"nswbmw","description":"Ip filter middleware for koa, support whitelist and blacklist.","archived":false,"fork":false,"pushed_at":"2023-03-02T07:42:09.000Z","size":27,"stargazers_count":37,"open_issues_count":0,"forks_count":9,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-24T11:03:44.084Z","etag":null,"topics":["blacklist","ip","koa","whitelist"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nswbmw.png","metadata":{"files":{"readme":"readme.md","changelog":"History.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-08-07T10:35:46.000Z","updated_at":"2024-04-04T05:48:54.000Z","dependencies_parsed_at":"2024-06-18T13:55:06.378Z","dependency_job_id":"f177b97f-4e7c-4692-ae51-c9b97dd83866","html_url":"https://github.com/nswbmw/koa-ip","commit_stats":{"total_commits":13,"total_committers":6,"mean_commits":"2.1666666666666665","dds":"0.46153846153846156","last_synced_commit":"354f2fc72353644b65f4f17505346324765f6eb6"},"previous_names":["mangrovetech/koa-ip"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nswbmw%2Fkoa-ip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nswbmw%2Fkoa-ip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nswbmw%2Fkoa-ip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nswbmw%2Fkoa-ip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nswbmw","download_url":"https://codeload.github.com/nswbmw/koa-ip/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251930209,"owners_count":21666773,"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","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":["blacklist","ip","koa","whitelist"],"created_at":"2024-08-04T00:01:12.341Z","updated_at":"2025-05-13T09:31:35.615Z","avatar_url":"https://github.com/nswbmw.png","language":"JavaScript","funding_links":[],"categories":["仓库"],"sub_categories":["中间件"],"readme":"## koa-ip\n\n\u003ca href=\"https://communityinviter.com/apps/koa-js/koajs\" rel=\"KoaJs Slack Community\"\u003e![KoaJs Slack](https://img.shields.io/badge/Koa.Js-Slack%20Channel-Slack.svg?longCache=true\u0026style=for-the-badge)\u003c/a\u003e \n\n\u003e koa-ip is a ip filter middleware for koa, support `whitelist` and `blacklist`.\n\n### Install\n\n```sh\n$ npm i koa-ip --save\n```\n\n### Usage\n\n```js\nip(String|RegExp)\nip(Array{String|RegExp})\nip({\n  whitelist: Array{String|RegExp},\n  blacklist: Array{String|RegExp},\n  handler: async (ctx, next) =\u003e {} // handle blacklist ip\n})\n```\n\n### Examples\n\n```js\nconst Koa = require('koa')\nconst ip = require('koa-ip')\n\nconst app = new Koa()\n\napp.use(ip('192.168.0.*')) // whitelist\n// app.use(ip(['192.168.0.*', '8.8.8.[0-3]'])) // whitelist\n// app.use(ip({\n//   whitelist: ['192.168.0.*', '8.8.8.[0-3]'],\n//   blacklist: ['144.144.*']\n// }))\n\napp.listen(3000)\n```\n\n#### blacklist handler\n\n```js\nconst app = new Koa()\napp.use((ctx, next) =\u003e {\n  ctx.request.ip = '127.0.0.1'\n  return next()\n})\napp.use(ip({\n  blacklist: ['127.0.0.*'],\n  handler: async (ctx, next) =\u003e {\n    ctx.status = 403\n  }\n}))\n\napp.use((ctx, next) =\u003e {\n  ctx.status = 200\n})\n\napp.listen(3000)\n```\n\n**NB**: If missing blacklist handler, default `ctx.status = 403`.\n\nMore examples see [test](./__tests__/).\n\n### Test\n\n```sh\n$ npm test (coverage 100%)\n```\n\n### License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnswbmw%2Fkoa-ip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnswbmw%2Fkoa-ip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnswbmw%2Fkoa-ip/lists"}