{"id":13799353,"url":"https://github.com/steambap/koa-tree-router","last_synced_at":"2026-01-28T21:38:43.040Z","repository":{"id":45568563,"uuid":"115835935","full_name":"steambap/koa-tree-router","owner":"steambap","description":"high performance router for Koa","archived":false,"fork":false,"pushed_at":"2026-01-14T03:40:10.000Z","size":368,"stargazers_count":138,"open_issues_count":7,"forks_count":11,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-14T07:22:59.877Z","etag":null,"topics":["fast","koa","koa-router","radix-tree"],"latest_commit_sha":null,"homepage":"","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/steambap.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2017-12-31T01:43:14.000Z","updated_at":"2026-01-14T03:40:14.000Z","dependencies_parsed_at":"2023-01-31T18:15:34.428Z","dependency_job_id":"a027a0bb-4f30-4e72-8b93-5245662b74af","html_url":"https://github.com/steambap/koa-tree-router","commit_stats":{"total_commits":92,"total_committers":5,"mean_commits":18.4,"dds":0.05434782608695654,"last_synced_commit":"08a88a612fdd1d2ffe98cb4326c6408e9919b38e"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/steambap/koa-tree-router","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steambap%2Fkoa-tree-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steambap%2Fkoa-tree-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steambap%2Fkoa-tree-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steambap%2Fkoa-tree-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/steambap","download_url":"https://codeload.github.com/steambap/koa-tree-router/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steambap%2Fkoa-tree-router/sbom","scorecard":{"id":850020,"data":{"date":"2025-08-11","repo":{"name":"github.com/steambap/koa-tree-router","commit":"cd33d2ba54714078d8a3ee7ad7269384c26f2089"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.6,"checks":[{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/nodejs.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/steambap/koa-tree-router/nodejs.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/steambap/koa-tree-router/nodejs.yml/main?enable=pin","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":2,"reason":"3 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 2/26 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"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"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 6 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-23T22:14:58.205Z","repository_id":45568563,"created_at":"2025-08-23T22:14:58.205Z","updated_at":"2025-08-23T22:14:58.205Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28853168,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T15:15:36.453Z","status":"ssl_error","status_checked_at":"2026-01-28T15:15:13.020Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["fast","koa","koa-router","radix-tree"],"created_at":"2024-08-04T00:01:01.856Z","updated_at":"2026-01-28T21:38:43.035Z","avatar_url":"https://github.com/steambap.png","language":"JavaScript","funding_links":[],"categories":["仓库"],"sub_categories":["中间件"],"readme":"# Koa tree router\r\n\r\n[![Build Status](https://github.com/steambap/koa-tree-router/workflows/CI/badge.svg)](https://github.com/steambap/koa-tree-router/actions?workflow=CI)\r\n[![npm](https://img.shields.io/npm/v/koa-tree-router.svg)](https://npm.im/koa-tree-router)\r\n![npm downloads](https://img.shields.io/npm/dt/koa-tree-router.svg)\r\n\r\nKoa tree router is a high performance router for Koa.\r\n\r\n## Features\r\n\r\n- Fast. Up to 11 times faster than Koa-router. [Benchmark](https://github.com/delvedor/router-benchmark)\r\n\r\n- Express-style routing using `router.get`, `router.put`, `router.post`, etc.\r\n\r\n- Support for `405 method not allowed`\r\n\r\n- Multiple middleware per route\r\n\r\n## How does it work?\r\n\r\nThe router relies on a tree structure which makes heavy use of *common prefixes*, it is basically a *compact* [*prefix tree*](https://en.wikipedia.org/wiki/Trie) (or just [*Radix tree*](https://en.wikipedia.org/wiki/Radix_tree)).\r\n\r\nThis module's tree implementation is based on [julienschmidt/httprouter](https://github.com/julienschmidt/httprouter).\r\n\r\n## Installation\r\n\r\n```sh\r\n# npm\r\nnpm i koa-tree-router\r\n# yarn\r\nyarn add koa-tree-router\r\n```\r\n\r\n## Usage\r\n\r\n```JS\r\nimport Koa from \"koa\";\r\nimport Router from \"koa-tree-router\";\r\n\r\nconst app = new Koa();\r\nconst router = new Router();\r\n\r\nrouter.get(\"/\", (ctx) =\u003e {\r\n  ctx.body = \"hello, world\";\r\n});\r\n\r\napp.use(router.routes());\r\n\r\napp.listen(8080);\r\n```\r\n\r\n## API\r\n\r\n#### Router([options])\r\nInstance a new router.  \r\n```js\r\nimport Router from \"koa-tree-router\";\r\n\r\nconst router = new Router({\r\n  onMethodNotAllowed(ctx) {\r\n    ctx.body = \"not allowed\";\r\n  },\r\n  ignoreTrailingSlash: true\r\n});\r\n```\r\n\r\n#### on(method, path, middleware)\r\nRegister a new route.\r\n```js\r\nrouter.on('GET', '/example', (ctx) =\u003e {\r\n  // your code\r\n})\r\n```\r\n\r\n#### Shorthand methods\r\nIf you want to get expressive, here is what you can do:\r\n```js\r\nrouter.get(path, middleware)\r\nrouter.delete(path, middleware)\r\nrouter.head(path, middleware)\r\nrouter.patch(path, middleware)\r\nrouter.post(path, middleware)\r\nrouter.put(path, middleware)\r\nrouter.options(path, middleware)\r\nrouter.trace(path, middleware)\r\nrouter.connect(path, middleware)\r\n```\r\n\r\nIf you need a route that supports *all* methods you can use the `all` api.\r\n```js\r\nrouter.all(path, middleware)\r\n```\r\n\r\n#### use(middleware)\r\nYou can add middleware that is added to all future routes:\r\n```js\r\nrouter.use(authMiddleware);\r\nrouter.get(\"/foo\", (ctx) =\u003e { /* your code */ });\r\nrouter.get(\"/bar\", (ctx) =\u003e { /* your code */ });\r\nrouter.get(\"/baz\", (ctx) =\u003e { /* your code */ });\r\n```\r\n\r\nThis is equivalent to:\r\n```js\r\nrouter.get(\"/foo\", authMiddleware, (ctx) =\u003e { /* your code */ });\r\nrouter.get(\"/bar\", authMiddleware, (ctx) =\u003e { /* your code */ });\r\nrouter.get(\"/baz\", authMiddleware, (ctx) =\u003e { /* your code */ });\r\n```\r\n**Caveat**: `use` must be called before register a new handler. It does not append handlers to registered routes.\r\n\r\n#### routes\r\nReturns router middleware.\r\n\r\n```JS\r\napp.use(router.routes());\r\n```\r\n\r\n#### nested routes\r\nA way to create groups of routes without incuring any per-request overhead.\r\n\r\n```js\r\nimport Koa from \"koa\";\r\nimport Router from \"koa-tree-router\";\r\n\r\nconst app = new Koa();\r\nconst router = new Router();\r\nconst group = router.newGroup(\"/foo\");\r\n// add a handler for /foo/bar\r\ngroup.get(\"/bar\", (ctx) =\u003e {\r\n  ctx.body = \"hello, world\";\r\n});\r\n\r\napp.use(router.routes());\r\n\r\napp.listen(8080);\r\n```\r\n\r\nMiddleware added with `use()` are also added to the nested routes.\r\n\r\n#### ctx.params\r\nThis object contains key-value pairs of named route parameters.\r\n\r\n```JS\r\nrouter.get(\"/user/:name\", function() {\r\n  // your code\r\n});\r\n// GET /user/1\r\nctx.params.name\r\n// =\u003e \"1\"\r\n```\r\n\r\n## How to write routes\r\nThere are 3 types of routes:\r\n\r\n1.Static\r\n```\r\nPattern: /static\r\n\r\n /static                   match\r\n /anything-else            no match\r\n```\r\n\r\n2.Named\r\n\r\nNamed parameters have the form `:name` and only match a single path segment:\r\n```\r\nPattern: /user/:user\r\n\r\n /user/gordon              match\r\n /user/you                 match\r\n /user/gordon/profile      no match\r\n /user/                    no match\r\n```\r\n\r\n3.Catch-all\r\n\r\nCatch-all parameters have the form `*name` and match everything. They must always be at the **end** of the pattern:\r\n\r\n```\r\nPattern: /src/*filepath\r\n\r\n /src/                     match\r\n /src/somefile.go          match\r\n /src/subdir/somefile.go   match\r\n```\r\n\r\n## Typescript Support\r\nThis package has its own declaration files in NPM package, you don't have to do anything extra.\r\n\r\n## License\r\n\r\n[MIT](LICENSE)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteambap%2Fkoa-tree-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsteambap%2Fkoa-tree-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteambap%2Fkoa-tree-router/lists"}