{"_id":"@defunctzombie/koa-autorouter","_rev":"4-1d4208049f9eb501e8dc738652c65889","name":"@defunctzombie/koa-autorouter","dist-tags":{"latest":"2.0.2"},"versions":{"1.0.0":{"name":"@defunctzombie/koa-autorouter","version":"1.0.0","license":"BlueOak-1.0.0","_id":"@defunctzombie/koa-autorouter@1.0.0","maintainers":[{"name":"defunctzombie","email":"shtylman@gmail.com"}],"dist":{"shasum":"adbb9ccd3460d9af2fede02d7cf1451da978b9c3","tarball":"https://registry.npmjs.org/@defunctzombie/koa-autorouter/-/koa-autorouter-1.0.0.tgz","fileCount":14,"integrity":"sha512-gJ+U4Jnu83bQxFmykVhrLKbM6IMtlg5A2fD8zHoVr6DpUBZ4K5fcbsbgR8MaL966M99QUQzSpcYRXPU1cfE73Q==","signatures":[{"sig":"MEUCIQCr4gQIIumLvTGc8wHJOWZTTfEgdMyOOWAAy+gSLN1LtgIgTrMs+TdVDZtOJ43MPdPCnmnU/AFRKVcNcLOc40iJohA=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":13535,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdvek2CRA9TVsSAnZWagAAcogP/RkmmNK2p1kC+AnmzFme\nvQG5LdmskWkypGxOii+9kF1eCGdLtKtwqVV1GIMVnYqnILjVTHDVDx677m8/\nXDHWSjcmbX+jzsAGien+MBUmoAbMeyYxdcNHf1Br2hPGBXHHkL5B5yvvTAkq\nLzgL1IzL7QysOaTOrkQXzkPVQ3+2Dk9tzE1UFhVcLqy/0Ihn90D92l7LGJji\nsHrmKClA9QD8jfaT8T86dtUMj803dDZ2UJ1RI3Zj/8l9w6M3Oa7GDQnc0qjN\nD0r/SZdg7XwHQb5Qw2/pKRRz2I7d6IMa5UWXLaFkd8mGbKXy+NgQaNzT30ID\npRMvdazCD8S+sa9rWxH3fv1KVypKw/2frDguJ9td30pXUl7FgNigDTSUVrhN\nFm9P+aZvP+EDKu8PIY5Vy/6ZVasB+JhHpEtAM0j3hFGuePwqbpOgHEaMhHI7\n+if4OtHWoL4d5g7whdqJ0zfzeVyPZuspmgUNfqM0Wz4O4JLXqKwY23AkHEIO\nQgduBw9cus0xvv0ipZ6riO0BQofjRHuBwtoB4A7Pi2c69dBX/f+rTxUuCadY\nYC7nWO4IL42SROQHxkuWDzCYj5kt9kpnDJ27zWjILBWh0YByE+W1cILN+KGn\nmnCfTuAGwPE9BLNCSJu4kTjkgTtRQP8+WDpgK4bAmRejsS8UnUMjRlp25Gwy\nJPDX\r\n=gCIB\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./lib/index.js","types":"./lib/index.d.ts","scripts":{"test":"jest","prepublish":"tsc"},"_npmUser":{"name":"defunctzombie","email":"shtylman@gmail.com"},"description":"Autorouter creates a koa router from a hierarchy of files and folders. A route is defined by the location and name of a file within a file system tree rather than string names in your application logic.","directories":{},"licenseText":"# Blue Oak Model License\n\nVersion 1.0.0\n\n## Purpose\n\nThis license gives everyone as much permission to work with\nthis software as possible, while protecting contributors\nfrom liability.\n\n## Acceptance\n\nIn order to receive this license, you must agree to its\nrules.  The rules of this license are both obligations\nunder that agreement and conditions to your license.\nYou must not do anything with this software that triggers\na rule that you cannot or will not follow.\n\n## Copyright\n\nEach contributor licenses you to do everything with this\nsoftware that would otherwise infringe that contributor's\ncopyright in it.\n\n## Notices\n\nYou must ensure that everyone who gets a copy of\nany part of this software from you, with or without\nchanges, also gets the text of this license or a link to\n<https://blueoakcouncil.org/license/1.0.0>.\n\n## Excuse\n\nIf anyone notifies you in writing that you have not\ncomplied with [Notices](#notices), you can keep your\nlicense by taking all practical steps to comply within 30\ndays after the notice.  If you do not do so, your license\nends immediately.\n\n## Patent\n\nEach contributor licenses you to do everything with this\nsoftware that would otherwise infringe any patent claims\nthey can license or become able to license.\n\n## Reliability\n\nNo contributor can revoke this license.\n\n## No Liability\n\n***As far as the law allows, this software comes as is,\nwithout any warranty or condition, and no contributor\nwill be liable to anyone for any damages related to this\nsoftware or this license, under any kind of legal claim.***\n\n","dependencies":{"koa-compose":"4.1.0","path-to-regexp":"3.1.0"},"_hasShrinkwrap":false,"devDependencies":{"koa":"2.11.0","jest":"24.9.0","ts-jest":"24.1.0","supertest":"4.0.2","@types/koa":"2.0.51","typescript":"3.6.4","@types/jest":"24.0.21","@types/node":"12.12.5","@types/supertest":"2.0.8"},"_npmOperationalInternal":{"tmp":"tmp/koa-autorouter_1.0.0_1572727094105_0.92173538268536","host":"s3://npm-registry-packages"}},"2.0.0":{"name":"@defunctzombie/koa-autorouter","version":"2.0.0","license":"BlueOak-1.0.0","_id":"@defunctzombie/koa-autorouter@2.0.0","maintainers":[{"name":"defunctzombie","email":"shtylman@gmail.com"}],"dist":{"shasum":"8902822d460210b20d768dd07b5d49e84bec298f","tarball":"https://registry.npmjs.org/@defunctzombie/koa-autorouter/-/koa-autorouter-2.0.0.tgz","fileCount":14,"integrity":"sha512-/UGNYPW0davUClFr0TnWHnN2nPMiiz7c6T2rxusnp82iwI4BTPh59i+qIQJzFek3bePS+gHribT+PMLslA453w==","signatures":[{"sig":"MEQCIGRdb7o0zZcVhw6ppwY+JIMP893o+dZEahy8KD1mJW2sAiBd5tM4JnxR0GUPEajh6P4FMjMBXnOwL40QEnQifGKK3w==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":16426,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJd683eCRA9TVsSAnZWagAA/0oP/RnS8C3VuDziNsEWH9a2\n/JsJC78zN22Z8ii4dAyRWmZZuDrAWpkT1IiUw1CMdiIu7iKsWfqnFvO7NEir\n+JrMwn9OqLSXp85ViyRe87takgRGJHrwyHzN2c43oDKIa4gUTCW8Z1iDYG4D\n8dGRhu2e8PkvxvT7ARzi8wnBolAJ5C+NSSSOWSZL3tCjbRXFRTpF73zQhAYs\nhCSfeGwzCco/vw9sHcBj/gfj5bq0Zt6pGh62KxIReIw+7NIUOzkU0vTR3cGJ\nTxJD8jNzcLBpzqCRQaBFeSbGHloJdvN2OXuss/fEkn+qrAOOiSFeAlfpc4Y4\nCAmSa8VxjCpp3GU0l1aF5rpg3a9jOJp38bD8bSwpub7bqE5fALTApI8Dy8p+\niSXDL6Tmruci1ZWtHyENT8hT4go+GwQI+WnVVcbrVmw3/KKN8Wlg11lH82sZ\nYakQjT8K6OiW/Yfq3yrcQYbYYL/Quuv6Pjig7GVtxuiBo4KHHmo/czTUKPoU\nPKZsftNrQowBsDD/o09Zl9m1QuPhxKHX7zuirS1vz87jxajvsaK4OOMw8coe\nu/UEHfudiPmfA1pkAZAWtqPfmk5ALCRHYEq98q8nqXLQtsKds2h7eSoJiHLC\nukVgzGBW6h77M35T9B6loWfYW+yw3yH7IPwgPtRtzw29fleEUTJEAomHaZYi\nNI7h\r\n=tHmS\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./lib/index.js","types":"./lib/index.d.ts","scripts":{"test":"jest","prepublish":"tsc"},"_npmUser":{"name":"defunctzombie","email":"shtylman@gmail.com"},"description":"Autorouter creates a koa router from a hierarchy of files and folders. A route is defined by the location and name of a file within a file system tree rather than string names in your application logic.","directories":{},"licenseText":"# Blue Oak Model License\n\nVersion 1.0.0\n\n## Purpose\n\nThis license gives everyone as much permission to work with\nthis software as possible, while protecting contributors\nfrom liability.\n\n## Acceptance\n\nIn order to receive this license, you must agree to its\nrules.  The rules of this license are both obligations\nunder that agreement and conditions to your license.\nYou must not do anything with this software that triggers\na rule that you cannot or will not follow.\n\n## Copyright\n\nEach contributor licenses you to do everything with this\nsoftware that would otherwise infringe that contributor's\ncopyright in it.\n\n## Notices\n\nYou must ensure that everyone who gets a copy of\nany part of this software from you, with or without\nchanges, also gets the text of this license or a link to\n<https://blueoakcouncil.org/license/1.0.0>.\n\n## Excuse\n\nIf anyone notifies you in writing that you have not\ncomplied with [Notices](#notices), you can keep your\nlicense by taking all practical steps to comply within 30\ndays after the notice.  If you do not do so, your license\nends immediately.\n\n## Patent\n\nEach contributor licenses you to do everything with this\nsoftware that would otherwise infringe any patent claims\nthey can license or become able to license.\n\n## Reliability\n\nNo contributor can revoke this license.\n\n## No Liability\n\n***As far as the law allows, this software comes as is,\nwithout any warranty or condition, and no contributor\nwill be liable to anyone for any damages related to this\nsoftware or this license, under any kind of legal claim.***\n\n","dependencies":{"koa-compose":"4.1.0","path-to-regexp":"3.2.0"},"_hasShrinkwrap":false,"devDependencies":{"koa":"2.11.0","jest":"24.9.0","ts-jest":"24.1.0","supertest":"4.0.2","@types/koa":"2.0.52","typescript":"3.7.2","@types/jest":"24.0.22","@types/node":"12.12.7","@types/supertest":"2.0.8"},"_npmOperationalInternal":{"tmp":"tmp/koa-autorouter_2.0.0_1575734749778_0.6613993299760983","host":"s3://npm-registry-packages"}},"2.0.1":{"name":"@defunctzombie/koa-autorouter","version":"2.0.1","license":"BlueOak-1.0.0","_id":"@defunctzombie/koa-autorouter@2.0.1","maintainers":[{"name":"defunctzombie","email":"shtylman@gmail.com"}],"dist":{"shasum":"365a7197b1b00a9717ef9b9666ddabaa1f0cce28","tarball":"https://registry.npmjs.org/@defunctzombie/koa-autorouter/-/koa-autorouter-2.0.1.tgz","fileCount":11,"integrity":"sha512-2xckhvP90TbMEmIhKiwT4RL7vSp3Ut+DKSE/4VNN64L9f4ZL1wQzwKsCBG0zyKfOwIuJ8piItSDNzfK/1w+RwQ==","signatures":[{"sig":"MEYCIQCzv9TCk0AT6f8JP+b4i0VjB8WldMgRwjnACYTuseIINwIhAJBjwVzQlftTIF/MAWIXQUe7Jse4c5FcbZm2PkIPtiOY","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":14801,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJej+teCRA9TVsSAnZWagAALB8P+gNS4RHVmyn1U41sCLzr\niz/rlowMPJJRXkFF/xMo7g0DpjF35eXLemLF+zm42J0CiN7GvFSFFKwHteuQ\n7VBGGYxRB69XvAU+gTRxXe8cLr7No/hL2VFakfDp1c99AFngQbDPp7Yq+DmJ\nOZqnJJP+TSbsbA1DR7fXkEzGQ6l3X+9NzHf8UL7CjdLFq1K+LyhuVKu7Gim3\npTR75oTXIOoZMu4Kw79z1BSMsW4kCTqATUfHDGHGSYHLtkAdwlsUb8WfBKOZ\nVNw347ciLlp3tM6K8eNsS6JDgQ69zKfT0KUad3LBC2UEUC735Wml/IklmMTv\ngBJI57U+pUtoUnkHYJmh/JuI7G0XJvTMvZoKGRwmlcMBLaZHx8UJTcF2LQm5\nEQSeAwCJlcoOfIBScacO5O6+msvdCG1pXJM8ze+5gwucBfLRqBGe0crRZIb5\n2XCZ7PVTu5o4QvM4Pa7VUaZtqVbOcCP8vb0koJhW7K+hBUV/0UmtzW9KycDB\ngoeer4hjSEL7Xga8/tXZqs1Pmdtmda/ydSLVN4P0bB60oWAArBb+R9zTz8KI\nlr5hfidIxgJ7xy1sM2Xxb3251bCwzfYR2GvlKhKjeelAtaOUDEyBh/N7LEwB\na812THMDNgohB1QOR/WUrJVa25ZRV6YIgjJp/RX+jog8hcjmzrBkBNW8PGGH\nfWy9\r\n=0St6\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./lib/index.js","types":"./lib/index.d.ts","scripts":{"test":"jest","prepublish":"tsc"},"_npmUser":{"name":"defunctzombie","email":"shtylman@gmail.com"},"description":"Autorouter creates a koa router from a hierarchy of files and folders. A route is defined by the location and name of a file within a file system tree rather than string names in your application logic.","directories":{},"licenseText":"# Blue Oak Model License\n\nVersion 1.0.0\n\n## Purpose\n\nThis license gives everyone as much permission to work with\nthis software as possible, while protecting contributors\nfrom liability.\n\n## Acceptance\n\nIn order to receive this license, you must agree to its\nrules.  The rules of this license are both obligations\nunder that agreement and conditions to your license.\nYou must not do anything with this software that triggers\na rule that you cannot or will not follow.\n\n## Copyright\n\nEach contributor licenses you to do everything with this\nsoftware that would otherwise infringe that contributor's\ncopyright in it.\n\n## Notices\n\nYou must ensure that everyone who gets a copy of\nany part of this software from you, with or without\nchanges, also gets the text of this license or a link to\n<https://blueoakcouncil.org/license/1.0.0>.\n\n## Excuse\n\nIf anyone notifies you in writing that you have not\ncomplied with [Notices](#notices), you can keep your\nlicense by taking all practical steps to comply within 30\ndays after the notice.  If you do not do so, your license\nends immediately.\n\n## Patent\n\nEach contributor licenses you to do everything with this\nsoftware that would otherwise infringe any patent claims\nthey can license or become able to license.\n\n## Reliability\n\nNo contributor can revoke this license.\n\n## No Liability\n\n***As far as the law allows, this software comes as is,\nwithout any warranty or condition, and no contributor\nwill be liable to anyone for any damages related to this\nsoftware or this license, under any kind of legal claim.***\n\n","dependencies":{"koa-compose":"4.1.0","path-to-regexp":"6.1.0"},"_hasShrinkwrap":false,"devDependencies":{"koa":"2.11.0","jest":"25.3.0","ts-jest":"25.3.1","supertest":"4.0.2","@types/koa":"2.11.3","typescript":"3.8.3","@types/jest":"25.2.1","@types/node":"13.11.1","@types/supertest":"2.0.8"},"_npmOperationalInternal":{"tmp":"tmp/koa-autorouter_2.0.1_1586490205802_0.38980361141514996","host":"s3://npm-registry-packages"}},"2.0.2":{"name":"@defunctzombie/koa-autorouter","version":"2.0.2","license":"BlueOak-1.0.0","dependencies":{"koa-compose":"4.1.0","path-to-regexp":"6.3.0"},"main":"./lib/index.js","types":"./lib/index.d.ts","devDependencies":{"@types/jest":"29.5.13","@types/koa":"2.15.0","@types/node":"22.7.4","@types/supertest":"6.0.2","jest":"29.7.0","koa":"2.15.3","supertest":"6.3.3","ts-jest":"29.2.5","typescript":"5.6.2"},"scripts":{"prepublish":"tsc -p tsconfig.build.json","test":"jest"},"packageManager":"yarn@1.22.19+sha512.ff4579ab459bb25aa7c0ff75b62acebe576f6084b36aa842971cf250a5d8c6cd3bc9420b22ce63c7f93a0857bc6ef29291db39c3e7a23aab5adfd5a4dd6c5d71","_id":"@defunctzombie/koa-autorouter@2.0.2","gitHead":"cb5a674957c664157cfc84de42fbf9cdd219fd4a","description":"Autorouter creates a koa router from a hierarchy of files and folders. A route is defined by the location and name of a file within a file system tree rather than string names in your application logic.","_nodeVersion":"22.2.0","_npmVersion":"10.7.0","dist":{"integrity":"sha512-mi5QOu1ZoOi9z9vFERA1A9tJSVcHwF+1bCEE0MfG3QJo19DfkWin6cQ8djpzxKbG+KrMvJLmoWjP4qBk4W3kmA==","shasum":"a482ae52c01e3fa838b9a195a7799c3250a55995","tarball":"https://registry.npmjs.org/@defunctzombie/koa-autorouter/-/koa-autorouter-2.0.2.tgz","fileCount":9,"unpackedSize":14939,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCaWIsGYNnn3aSMdc2WjStzs+XysKDgZqt9JCB5HlAdzgIhAKakJKTIwz92aBRKV9JcxnQ5FpeslrlsIi7PBXJfnv75"}]},"_npmUser":{"name":"defunctzombie","email":"shtylman@gmail.com"},"directories":{},"maintainers":[{"name":"defunctzombie","email":"shtylman@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/koa-autorouter_2.0.2_1727480379484_0.5884241591971464"},"_hasShrinkwrap":false}},"time":{"created":"2019-11-02T20:38:13.879Z","modified":"2024-09-27T23:39:39.870Z","1.0.0":"2019-11-02T20:38:14.293Z","2.0.0":"2019-12-07T16:05:49.937Z","2.0.1":"2020-04-10T03:43:25.960Z","2.0.2":"2024-09-27T23:39:39.674Z"},"license":"BlueOak-1.0.0","description":"Autorouter creates a koa router from a hierarchy of files and folders. A route is defined by the location and name of a file within a file system tree rather than string names in your application logic.","maintainers":[{"name":"defunctzombie","email":"shtylman@gmail.com"}],"readme":"# koa-autorouter\n\nAutorouter creates a koa router from a hierarchy of files and folders. A route is defined by the location and name of a file within a file system tree rather than string names in your application logic.\n\nThis module helps me organize my code and routes into smaller logic components while redicing boilerplate to create routers manually.\n\n```typescript\nimport Router from '@defunctzombie/koa-autorouter';\n\nconst app = new Koa();\n\nconst router = new Router({\n    root: '/path/to/routes/folder',\n})\napp.use(router.middleware());\n```\n\n## Defining Routes\n\nA route is defined by a file under the routes folder. Files should default export a function which will accept a Route instance on which you can attach handlers to specific HTTP verbs.\n\nBelow is an example with two routes: An index route and a status-endpoint route. The index route will receive requests for `/` and the status-endpoint route will receive requests for `/status-endpoint`.\n\n```\n/\n/index.ts\n/status-endpoint.ts\n```\n\nLooking at `index.ts`\n\n```typescript\nimport { Route } from '@defunctzombie/autorouter';\n\nexport default (route: Route) => {\n    route.get(async (req, res) => {\n        res.body = 'Hello World!';\n    });\n}\n```\n\nAnd `status-endpoint.ts`\n\n```typescript\nimport { Route } from '@defunctzombie/autorouter';\n\nexport default (route: Route) => {\n     route.get(async (req, res) => {\n        res.body = {\n            health: 'good',\n        }\n     });\n};\n```\n\nThe `Route` interface supports all HTTP Verbs (get, put, ...). Here we have defined routes which only support GET requests. If we wanted to support other verbs we would need to invoke the appropriate methods on the route instance.\n\n`req` and `res` are the `Request` and `Response` instances from the koa `context`. See the koa documentation on appropriate methods and parameters when accessing those objects.\n\n## Parameterized Routes\n\nA parameterized route is a route where part of the url can vary and is not known during route setup. An example would be the route `/posts/1234`. Here `1234` could be the post ID yet we do not know this ID when we setup our routes.\n\nTo define a parameterized route, use `[parameterName]` when naming the file. For our posts example, we would create a route file `posts/[postId].ts`. The router will understand `[postId]` indicates a parameterized route and pass requests to our route.\n\nThe route setup is defined as:\n\n```typescript\nexport default (route: Route<{ postId: string }>) {\n    route.get(async (req, res) => {\n        // echo the post id\n        res.body = {\n            postId: req.params.postId,\n        }\n    });\n}\n```\n\nNotice the additional `{ postId: string}` generic argument to our `Route` type. This indicates the request expects a parameter called `postId`. The `req` instance will be extended with the parameter type inforamtion.\n\n> GOTCHA: The request parameter generic argument is not type validated against the route filename. You must ensure the parameter name in the file path matches the argument name. \n\n## Passthrough Routes\n\nA passthrough route (aka middleware) is defined by invoking the `use` method on the route instance.\n\nFor example - we want to make sure that all routes under `/foo` contain a specific header. We would create a route file at `foo/index.ts` under our route root and implement the `use` method.\n\n```typescript\nimport { Route } from '@defunctzombie/autorouter';\n\nexport default (route: Route<{ postId: string }>) {\n    route.use(async (req, res, next) => {\n        if (!req.get('my-header')) {\n            res.status = 403;\n            return;\n        }\n        await next();\n    });\n}\n```\n\n## Ignoring Test Files\n\nIf you co-locate your tests with your routes, as shown in this repo under the `test-routes` folder, you will use the `ignorePattern` Router option.\n\n```typescript\nconst router = new Router({\n    root: '/path/to/routes/folder',\n    ignorePattern: 'test.ts',\n})\n```\n\nThe `ignorePattern` option tests file paths against the regex pattern. If the file path matches, the file is ignored by the router.\n\n## Requirements\n\nThis module is built with typescript and requires **nodejs 10.3+** for ES2018 support.\n\nTypescript declaration support is included.\n\n## License\n\nBlueOak-1.0.0","readmeFilename":"README.md"}