{"name":"@eggjs/koa","version":"3.1.0-beta.2","keywords":["web","app","http","application","framework","middleware","rack"],"license":"MIT","_id":"@eggjs/koa@3.1.0-beta.2","maintainers":[{"name":"gxkl","email":"gxkl203@gmail.com"},{"name":"eggjs-admin","email":"fengmk2+eggjs@gmail.com"},{"name":"fengmk2","email":"fengmk2@gmail.com"},{"name":"atian25","email":"atian25@qq.com"},{"name":"hyj1991","email":"yeekwanvong@gmail.com"},{"name":"killagu","email":"killa07071201@gmail.com"},{"name":"coolme200","email":"2001-wms@163.com"},{"name":"akitasummer","email":"akitasummer@outlook.com"}],"homepage":"https://github.com/eggjs/egg#readme","bugs":{"url":"https://github.com/eggjs/egg/issues"},"dist":{"shasum":"122059d727ded62e9157e9a453e41bddcc46b72a","tarball":"http://registry-npm.ywwl.com/@eggjs/koa/download/@eggjs/koa-3.1.0-beta.2.tgz","fileCount":14,"integrity":"sha512-oC1xjQEuHkbJugKCRP2CKkeyRtcxuSmHG0I50pyK92URooeBw1MkdUmd/GXtMY/nqq2qBmRnuAZGrRRFz7ZASw==","signatures":[{"sig":"MEUCIHoa/2wARtc139lcvUVOcmFjXVxQicfy9ScN2qhGd0ssAiEA1iZqWobst5YthbGzZavlpjlgPeKHQN4dyhL31ksGUBM=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@eggjs%2fkoa@3.1.0-beta.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":70511,"size":19233,"noattachment":false,"key":"/@eggjs/koa/-/@eggjs/koa-3.1.0-beta.2.tgz"},"main":"./dist/index.js","type":"module","_from":"file:eggjs-koa-3.1.0-beta.2.tgz","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">= 20.19.0"},"exports":{".":"./dist/index.js","./package.json":"./package.json"},"scripts":{"test":"vitest run","build":"tsdown"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:55253768-a1be-48a9-8a20-2214b6dad71b"}},"_resolved":"/tmp/b53cb5474441a94a752574d1f9ceb641/eggjs-koa-3.1.0-beta.2.tgz","_integrity":"sha512-oC1xjQEuHkbJugKCRP2CKkeyRtcxuSmHG0I50pyK92URooeBw1MkdUmd/GXtMY/nqq2qBmRnuAZGrRRFz7ZASw==","repository":{"url":"git://github.com/eggjs/egg.git","type":"git","directory":"packages/koa"},"_npmVersion":"11.6.0","description":"Koa web app framework for https://eggjs.org","directories":{},"_nodeVersion":"22.19.0","dependencies":{"gals":"1","vary":"^1.1.2","fresh":"~0.5.2","accepts":"^1.3.8","cookies":"^0.9.1","destroy":"^1.0.4","type-is":"^1.6.18","parseurl":"^1.3.3","statuses":"^2.0.1","encodeurl":"^1.0.2","is-type-of":"^2.2.0","escape-html":"^1.0.3","http-errors":"^2.0.0","koa-compose":"^4.1.0","on-finished":"^2.4.1","content-type":"^1.0.5","cache-content-type":"^2.0.0","content-disposition":"~0.5.4","@types/content-disposition":"^0.5.8"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"mm":"^4.0.2","tsdown":"^0.14.2","supertest":"^3.1.0","typescript":"5","@types/node":"24","@types/vary":"^1.1.3","@types/fresh":"^0.5.2","@types/accepts":"^1.3.7","@types/cookies":"^0.9.0","@types/destroy":"^1.0.3","@types/type-is":"^1.6.6","@types/parseurl":"^1.3.3","@types/statuses":"^2.0.5","@types/encodeurl":"^1.0.2","@types/supertest":"^6.0.2","@types/escape-html":"^1.0.4","@types/http-errors":"^2.0.4","@types/koa-compose":"^3.2.8","@types/on-finished":"^2.3.4","@types/content-type":"^1.1.8"},"_npmOperationalInternal":{"tmp":"tmp/koa_3.1.0-beta.2_1757780792384_0.8775785660176934","host":"s3://npm-registry-packages-npm-production"},"readme":"# @eggjs/koa\n\n@eggjs/koa is forked from [Koa v2.x](https://github.com/koajs/koa/tree/v2.x) for LTS and supports Node.js >=22.18.0.\n\n<img height=\"240px\" src=\"/docs/logo.png\" alt=\"Koa middleware framework for nodejs\"/>\n\n[![NPM version](https://img.shields.io/npm/v/@eggjs/koa.svg?style=flat-square)](https://npmjs.org/package/@eggjs/koa)\n[![NPM download](https://img.shields.io/npm/dm/@eggjs/koa.svg?style=flat-square)](https://npmjs.org/package/@eggjs/koa)\n[![Known Vulnerabilities](https://snyk.io/test/npm/@eggjs/koa/badge.svg?style=flat-square)](https://snyk.io/test/npm/@eggjs/koa)\n\nExpressive HTTP middleware framework for node.js to make web applications and APIs more enjoyable to write. Koa's middleware stack flows in a stack-like manner, allowing you to perform actions downstream then filter and manipulate the response upstream.\n\nOnly methods that are common to nearly all HTTP servers are integrated directly into Koa's small codebase.\nThis includes things like content negotiation, normalization of node inconsistencies, redirection, and a few others.\n\nKoa is not bundled with any middleware.\n\n## Installation\n\n@eggjs/koa@3 requires **node v22.18.0** or higher for Node.js LTS support.\n\n```bash\nnpm install @eggjs/koa\n```\n\n## Hello Koa\n\n```ts\nimport { Application } from '@eggjs/koa';\n\nconst app = new Application();\n\n// response\napp.use((ctx) => {\n  ctx.body = 'Hello Koa';\n});\n\napp.listen(3000);\n```\n\n## Getting started\n\n- [Kick-Off-Koa](https://github.com/koajs/kick-off-koa) - An intro to Koa via a set of self-guided workshops.\n- [Workshop](https://github.com/koajs/workshop) - A workshop to learn the basics of Koa, Express' spiritual successor.\n- [Introduction Screencast](https://knowthen.com/episode-3-koajs-quickstart-guide/) - An introduction to installing and getting started with Koa\n\n## Middleware\n\nKoa is a middleware framework that can take two different kinds of functions as middleware:\n\n- async function\n- common function\n\nHere is an example of logger middleware with each of the different functions:\n\n### **_async_** functions\n\n```ts\napp.use(async (ctx, next) => {\n  const start = Date.now();\n  await next();\n  const ms = Date.now() - start;\n  console.log(`${ctx.method} ${ctx.url} - ${ms}ms`);\n});\n```\n\n### Common function\n\n```ts\n// Middleware normally takes two parameters (ctx, next), ctx is the context for one request,\n// next is a function that is invoked to execute the downstream middleware. It returns a Promise with a then function for running code after completion.\n\napp.use((ctx, next) => {\n  const start = Date.now();\n  return next().then(() => {\n    const ms = Date.now() - start;\n    console.log(`${ctx.method} ${ctx.url} - ${ms}ms`);\n  });\n});\n```\n\n## Context, Request and Response\n\nEach middleware receives a Koa `Context` object that encapsulates an incoming\nhttp message and the corresponding response to that message. `ctx` is often used\nas the parameter name for the context object.\n\n```ts\napp.use(async (ctx, next) => {\n  await next();\n});\n```\n\nKoa provides a `Request` object as the `request` property of the `Context`.  \nKoa's `Request` object provides helpful methods for working with\nhttp requests which delegate to an [IncomingMessage](https://nodejs.org/api/http.html#http_class_http_incomingmessage)\nfrom the node `http` module.\n\nHere is an example of checking that a requesting client supports xml.\n\n```ts\napp.use(async (ctx, next) => {\n  ctx.assert(ctx.request.accepts('xml'), 406);\n  // equivalent to:\n  // if (!ctx.request.accepts('xml')) ctx.throw(406);\n  await next();\n});\n```\n\nKoa provides a `Response` object as the `response` property of the `Context`.  \nKoa's `Response` object provides helpful methods for working with\nhttp responses which delegate to a [ServerResponse](https://nodejs.org/api/http.html#http_class_http_serverresponse)\n.\n\nKoa's pattern of delegating to Node's request and response objects rather than extending them\nprovides a cleaner interface and reduces conflicts between different middleware and with Node\nitself as well as providing better support for stream handling. The `IncomingMessage` can still be\ndirectly accessed as the `req` property on the `Context` and `ServerResponse` can be directly\naccessed as the `res` property on the `Context`.\n\nHere is an example using Koa's `Response` object to stream a file as the response body.\n\n```ts\napp.use(async (ctx, next) => {\n  await next();\n  ctx.response.type = 'xml';\n  ctx.response.body = fs.createReadStream('really_large.xml');\n});\n```\n\nThe `Context` object also provides shortcuts for methods on its `request` and `response`. In the prior\nexamples, `ctx.type` can be used instead of `ctx.response.type` and `ctx.accepts` can be used\ninstead of `ctx.request.accepts`.\n\nFor more information on `Request`, `Response` and `Context`, see the [Request API Reference](docs/api/request.md),\n[Response API Reference](docs/api/response.md) and [Context API Reference](docs/api/context.md).\n\n## Koa Application\n\nThe object created when executing `new Koa()` is known as the Koa application object.\n\nThe application object is Koa's interface with node's http server and handles the registration\nof middleware, dispatching to the middleware from http, default error handling, as well as\nconfiguration of the context, request and response objects.\n\nLearn more about the application object in the [Application API Reference](docs/api/index.md).\n\n## Documentation\n\n- [Usage Guide](docs/guide.md)\n- [Error Handling](docs/error-handling.md)\n- [Koa for Express Users](docs/koa-vs-express.md)\n- [FAQ](docs/faq.md)\n- [API documentation](docs/api/index.md)\n\n## Troubleshooting\n\nCheck the [Troubleshooting Guide](docs/troubleshooting.md) or [Debugging Koa](docs/guide.md#debugging-koa) in\nthe general Koa guide.\n\n## Running tests\n\n```bash\nnpm test\n```\n\n## Reporting vulnerabilities\n\nTo report a security vulnerability, please do not open an issue, as this notifies attackers of the vulnerability. Instead, please email [fengmk2](mailto:fengmk2+eggjs@gmail.com) to disclose.\n\n## Community\n\n- [Examples](https://github.com/koajs/examples)\n- [Middleware](https://github.com/koajs/koa/wiki) list\n- [Wiki](https://github.com/koajs/koa/wiki)\n- [中文文档 v2.x](https://github.com/demopark/koa-docs-Zh-CN)\n\n## License\n\n[MIT](LICENSE)\n\n## Contributors\n\n[![Contributors](https://contrib.rocks/image?repo=eggjs/egg)](https://github.com/eggjs/egg/graphs/contributors)\n\nMade with [contributors-img](https://contrib.rocks).\n","publish_time":1757780792565,"_cnpm_publish_time":1757780792565,"dist-tags":{"alpha":"3.0.0-alpha.0","beta":"3.1.2-beta.27","latest":"3.2.0","rc":"3.1.2-rc.1","release-2.x":"2.22.2"}}