{"id":13779219,"url":"https://github.com/koajs/cors","last_synced_at":"2025-04-13T01:59:15.209Z","repository":{"id":27054979,"uuid":"30520411","full_name":"koajs/cors","owner":"koajs","description":"Cross-Origin Resource Sharing(CORS) for koa","archived":false,"fork":false,"pushed_at":"2024-03-02T23:01:34.000Z","size":118,"stargazers_count":741,"open_issues_count":21,"forks_count":80,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-04-13T01:58:58.930Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","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":"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}},"created_at":"2015-02-09T05:34:31.000Z","updated_at":"2025-03-19T04:41:53.000Z","dependencies_parsed_at":"2024-01-02T07:04:41.793Z","dependency_job_id":"8a12b5ff-f6c9-4527-8755-0a91e26a6cc1","html_url":"https://github.com/koajs/cors","commit_stats":{"total_commits":59,"total_committers":20,"mean_commits":2.95,"dds":0.6271186440677966,"last_synced_commit":"18a43f0e66cab2f46d50e8500cafc13930aad68e"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fcors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fcors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fcors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fcors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koajs","download_url":"https://codeload.github.com/koajs/cors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248654047,"owners_count":21140235,"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-03T18:01:02.702Z","updated_at":"2025-04-13T01:59:15.183Z","avatar_url":"https://github.com/koajs.png","language":"JavaScript","readme":"# @koa/cors\n\n[![NPM version][npm-image]][npm-url]\n[![Node.js CI](https://github.com/koajs/cors/actions/workflows/nodejs.yml/badge.svg)](https://github.com/koajs/cors/actions/workflows/nodejs.yml)\n[![Test coverage][codecov-image]][codecov-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/@koa/cors.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/@koa/cors\n[codecov-image]: https://codecov.io/github/koajs/cors/coverage.svg?branch=v2.x\n[codecov-url]: https://codecov.io/github/koajs/cors?branch=v2.x\n[download-image]: https://img.shields.io/npm/dm/@koa/cors.svg?style=flat-square\n[download-url]: https://npmjs.org/package/@koa/cors\n\n[Cross-Origin Resource Sharing(CORS)](https://developer.mozilla.org/en/docs/Web/HTTP/Access_control_CORS) for koa\n\n## Installation\n\n```bash\n$ npm install @koa/cors --save\n```\n\n## Quick start\n\nEnable cors with default options:\n\n- origin: `*` (v4 and before: the request's Origin header). This means that **by default the requests from all origin webpages will be allowed**.\n  If you're running a generic API server, this is what you want, but otherwise you should look into changing the default to something more\n  suitable to your application.\n- allowMethods: GET,HEAD,PUT,POST,DELETE,PATCH\n\n```js\nconst Koa = require('koa');\nconst cors = require('@koa/cors');\n\nconst app = new Koa();\napp.use(cors());\n```\n\n## cors(options)\n\n```js\n/**\n * CORS middleware\n *\n * @param {Object} [options]\n *  - {String|Function(ctx)} origin `Access-Control-Allow-Origin`, default is '*'\n *    If `credentials` set and return `true, the `origin` default value will set to the request `Origin` header\n *  - {String|Array} allowMethods `Access-Control-Allow-Methods`, default is 'GET,HEAD,PUT,POST,DELETE,PATCH'\n *  - {String|Array} exposeHeaders `Access-Control-Expose-Headers`\n *  - {String|Array} allowHeaders `Access-Control-Allow-Headers`\n *  - {String|Number} maxAge `Access-Control-Max-Age` in seconds\n *  - {Boolean|Function(ctx)} credentials `Access-Control-Allow-Credentials`, default is false.\n *  - {Boolean} keepHeadersOnError Add set headers to `err.header` if an error is thrown\n *  - {Boolean} secureContext `Cross-Origin-Opener-Policy` \u0026 `Cross-Origin-Embedder-Policy` headers.', default is false\n *  - {Boolean} privateNetworkAccess handle `Access-Control-Request-Private-Network` request by return `Access-Control-Allow-Private-Network`, default to false\n * @return {Function} cors middleware\n * @api public\n */\n```\n\n## Breaking change between 4.0 and 5.0\n\nThe default `origin` is set to `*`, if you want to keep the 4.0 behavior, you can set the `origin` handler like this:\n\n```js\napp.use(cors({\n  origin(ctx) {\n    return ctx.get('Origin') || '*';\n  },\n}));\n```\n\n## License\n\n[MIT](./LICENSE)\n\n\u003c!-- GITCONTRIBUTOR_START --\u003e\n\n## Contributors\n\n|[\u003cimg src=\"https://avatars.githubusercontent.com/u/156269?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003efengmk2\u003c/b\u003e\u003c/sub\u003e](https://github.com/fengmk2)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/985607?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003edead-horse\u003c/b\u003e\u003c/sub\u003e](https://github.com/dead-horse)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/1127384?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003eomsmith\u003c/b\u003e\u003c/sub\u003e](https://github.com/omsmith)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/643505?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003ejonathanong\u003c/b\u003e\u003c/sub\u003e](https://github.com/jonathanong)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/5622516?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003eAlphaWong\u003c/b\u003e\u003c/sub\u003e](https://github.com/AlphaWong)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/55783048?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003ecma-skedulo\u003c/b\u003e\u003c/sub\u003e](https://github.com/cma-skedulo)\u003cbr/\u003e|\n| :---: | :---: | :---: | :---: | :---: | :---: |\n|[\u003cimg src=\"https://avatars.githubusercontent.com/u/6992588?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003eCleberRossi\u003c/b\u003e\u003c/sub\u003e](https://github.com/CleberRossi)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/178720?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003eerikfried\u003c/b\u003e\u003c/sub\u003e](https://github.com/erikfried)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/1217939?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003ej-waaang\u003c/b\u003e\u003c/sub\u003e](https://github.com/j-waaang)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/4184677?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003eltomes\u003c/b\u003e\u003c/sub\u003e](https://github.com/ltomes)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/372420?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003elfreneda\u003c/b\u003e\u003c/sub\u003e](https://github.com/lfreneda)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/170299?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003ematthewmueller\u003c/b\u003e\u003c/sub\u003e](https://github.com/matthewmueller)\u003cbr/\u003e|\n[\u003cimg src=\"https://avatars.githubusercontent.com/u/6006498?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003ePlasmaPower\u003c/b\u003e\u003c/sub\u003e](https://github.com/PlasmaPower)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/14932834?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003eswain\u003c/b\u003e\u003c/sub\u003e](https://github.com/swain)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/49938086?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003eTyrealHu\u003c/b\u003e\u003c/sub\u003e](https://github.com/TyrealHu)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/8369011?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003exg-wang\u003c/b\u003e\u003c/sub\u003e](https://github.com/xg-wang)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/12003270?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003elishengzxc\u003c/b\u003e\u003c/sub\u003e](https://github.com/lishengzxc)\u003cbr/\u003e|[\u003cimg src=\"https://avatars.githubusercontent.com/u/514097?v=4\" width=\"100px;\"/\u003e\u003cbr/\u003e\u003csub\u003e\u003cb\u003emcohen75\u003c/b\u003e\u003c/sub\u003e](https://github.com/mcohen75)\u003cbr/\u003e\n\nThis project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Sat Oct 08 2022 21:35:10 GMT+0800`.\n\n\u003c!-- GITCONTRIBUTOR_END --\u003e\n","funding_links":[],"categories":["JavaScript","Middleware","仓库","Koa Middlewares"],"sub_categories":["中间件"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Fcors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoajs%2Fcors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Fcors/lists"}