{"id":13527277,"url":"https://github.com/koajs/mount","last_synced_at":"2025-05-13T23:06:52.749Z","repository":{"id":485408,"uuid":"12174738","full_name":"koajs/mount","owner":"koajs","description":"Mount other Koa applications or middleware to a given pathname","archived":false,"fork":false,"pushed_at":"2025-04-28T03:15:52.000Z","size":170,"stargazers_count":554,"open_issues_count":6,"forks_count":51,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-29T05:03:15.378Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/koajs.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,"zenodo":null}},"created_at":"2013-08-17T06:48:38.000Z","updated_at":"2025-04-27T08:01:37.000Z","dependencies_parsed_at":"2025-04-13T20:17:45.003Z","dependency_job_id":"2ea6ed24-94b7-4f5f-b01f-59302191b826","html_url":"https://github.com/koajs/mount","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fmount","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fmount/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fmount/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fmount/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koajs","download_url":"https://codeload.github.com/koajs/mount/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251874767,"owners_count":21658067,"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":[],"created_at":"2024-08-01T06:01:44.804Z","updated_at":"2025-05-13T23:06:52.730Z","avatar_url":"https://github.com/koajs.png","language":"JavaScript","readme":"# koa-mount\n\n  Mount other Koa applications as middleware. The `path` passed to `mount()` is stripped\n  from the URL temporarily until the stack unwinds. This is useful for creating entire\n  apps or middleware that will function correctly regardless of which path segment(s)\n  they should operate on.\n\n## Installation\n\n```js\n$ npm install koa-mount\n```\n\n## Examples\n\n  View the [./examples](examples) directory for working examples.\n\n### Mounting Applications\n\n  Entire applications mounted at specific paths. For example you could mount\n  a blog application at \"/blog\", with a router that matches paths such as\n  \"GET /\", \"GET /posts\", and will behave properly for \"GET /blog/posts\" etc\n  when mounted.\n\n```js\nconst mount = require('koa-mount');\nconst Koa = require('koa');\n\n// hello\n\nconst a = new Koa();\n\na.use(async function (ctx, next){\n  await next();\n  ctx.body = 'Hello';\n});\n\n// world\n\nconst b = new Koa();\n\nb.use(async function (ctx, next){\n  await next();\n  ctx.body = 'World';\n});\n\n// app\n\nconst app = new Koa();\n\napp.use(mount('/hello', a));\napp.use(mount('/world', b));\n\napp.listen(3000);\nconsole.log('listening on port 3000');\n```\n\n  Try the following requests:\n\n```\n$ GET /\nNot Found\n\n$ GET /hello\nHello\n\n$ GET /world\nWorld\n```\n\n### Mounting Middleware\n\n  Mount middleware at specific paths, allowing them to operate independently\n  of the prefix, as they're not aware of it.\n\n```js\nconst mount = require('koa-mount');\nconst Koa = require('koa');\n\nasync function hello(ctx, next){\n  await next();\n  ctx.body = 'Hello';\n}\n\nasync function world(ctx, next){\n  await next();\n  ctx.body = 'World';\n}\n\nconst app = new Koa();\n\napp.use(mount('/hello', hello));\napp.use(mount('/world', world));\n\napp.listen(3000);\nconsole.log('listening on port 3000');\n```\n\n### Optional Paths\n\n  The path argument is optional, defaulting to \"/\":\n\n```js\napp.use(mount(a));\napp.use(mount(b));\n```\n\n## Debugging\n\n  Use the __DEBUG__ environement variable to whitelist\n  koa-mount debug output:\n\n```\n$ DEBUG=koa-mount node myapp.js \u0026\n$ GET /foo/bar/baz\n\n  koa-mount enter /foo/bar/baz -\u003e /bar/baz +2s\n  koa-mount enter /bar/baz -\u003e /baz +0ms\n  koa-mount enter /baz -\u003e / +0ms\n  koa-mount leave /baz -\u003e / +1ms\n  koa-mount leave /bar/baz -\u003e /baz +0ms\n  koa-mount leave /foo/bar/baz -\u003e /bar/baz +0ms\n```\n\n## License\n\n  MIT\n","funding_links":[],"categories":["JavaScript","Middleware","仓库"],"sub_categories":["中间件"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Fmount","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoajs%2Fmount","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Fmount/lists"}