{"id":14989678,"url":"https://github.com/qianlongo/pure-koa-router","last_synced_at":"2025-04-12T01:41:16.000Z","repository":{"id":79425979,"uuid":"145130490","full_name":"qianlongo/pure-koa-router","owner":"qianlongo","description":"一个将路由配置和控制器分离的koa中间件","archived":false,"fork":false,"pushed_at":"2019-03-10T11:46:18.000Z","size":68,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T21:21:59.780Z","etag":null,"topics":["koa","koa-router","koa2","nodejs"],"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/qianlongo.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-17T14:27:42.000Z","updated_at":"2021-03-15T09:58:34.000Z","dependencies_parsed_at":"2023-05-11T17:45:33.230Z","dependency_job_id":null,"html_url":"https://github.com/qianlongo/pure-koa-router","commit_stats":{"total_commits":19,"total_committers":2,"mean_commits":9.5,"dds":"0.052631578947368474","last_synced_commit":"63b7c18a396efb666f434e3bf1016087e7c7dd20"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qianlongo%2Fpure-koa-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qianlongo%2Fpure-koa-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qianlongo%2Fpure-koa-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qianlongo%2Fpure-koa-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qianlongo","download_url":"https://codeload.github.com/qianlongo/pure-koa-router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248505742,"owners_count":21115352,"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":["koa","koa-router","koa2","nodejs"],"created_at":"2024-09-24T14:18:44.994Z","updated_at":"2025-04-12T01:41:15.981Z","avatar_url":"https://github.com/qianlongo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## pure-koa-router\n\n\u003e 一个将路由配置和控制器分离的koa中间件\n\n[你可能会用到的一个路由适配器](https://github.com/qianlongo/blog/issues/27)\n\n\n## 使用\n\n\u003e npm i pure-koa-router -S\n\n``` javascript\nconst Koa = require('koa')\nconst pureKoaRouter = require('pure-koa-router')\nconst path = require('path')\n\nconst app = new Koa()\n\n// const routes = require('../routes') 传文件内容，数组\n// const routes = path.join(__dirname, '../routes') 传文件目录\n// const routes = path.join(__dirname, '../routes/tasks.js') 传文件名称\n\nconst controllerDir = path.join(__dirname, '../controller') // 指定控制器的根目录\nconst routerOptions = { // new KoaRouter() 时候传入的参数 具体点击https://github.com/alexmingoia/koa-router\n  prefix: '/users'\n}\n\napp.use(pureKoaRouter({\n  routes,\n  controllerDir,\n  routerOptions\n}))\n\n\n```\n\n## routes配置 ([也可以参考例子](https://github.com/qianlongo/pure-koa-router/tree/master/example/routes))\n\n```\n// path 支持字符串  数组 正则\n// methods 支持字符串  数组\n// middleware 支持字符串  数组\n\n// 1 最基础的配置\n{\n  path: '/test',\n  methods: 'post',\n  controller: 'test.index'\n}\n\n// 2 对同一个path支持多个controller处理\n{\n  path: '/test',\n  methods: 'post',\n  controller: [ 'test.index', 'apply.test.index2' ]\n}\n\n// 支持多个path指向同一个controller\n{\n  path: [ '/test', '/test2' ],\n  controller: 'test.index'\n}\n```\n\n## 更新记录\n\n1.0.0  第一个版本\n\n1.0.1 修改文档说明\n\n1.0.2 支持方法为all的情况支持\n\n1.0.3 添加获取文件异常处理\n\n1.0.4 修复method为all时路由匹配有问题的bug\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqianlongo%2Fpure-koa-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqianlongo%2Fpure-koa-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqianlongo%2Fpure-koa-router/lists"}