{"id":16184045,"url":"https://github.com/fralonra/corsen","last_synced_at":"2025-04-07T12:45:16.183Z","repository":{"id":57209571,"uuid":"221913925","full_name":"fralonra/corsen","owner":"fralonra","description":"A universal Cross-Origin Resource Sharing(CORS) middleware","archived":false,"fork":false,"pushed_at":"2019-11-17T04:20:30.000Z","size":46,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-15T13:16:08.219Z","etag":null,"topics":["cors","middleware"],"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/fralonra.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}},"created_at":"2019-11-15T11:50:29.000Z","updated_at":"2019-11-17T04:20:33.000Z","dependencies_parsed_at":"2022-09-01T13:10:24.115Z","dependency_job_id":null,"html_url":"https://github.com/fralonra/corsen","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fralonra%2Fcorsen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fralonra%2Fcorsen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fralonra%2Fcorsen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fralonra%2Fcorsen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fralonra","download_url":"https://codeload.github.com/fralonra/corsen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247655545,"owners_count":20974196,"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":["cors","middleware"],"created_at":"2024-10-10T07:08:49.020Z","updated_at":"2025-04-07T12:45:16.156Z","avatar_url":"https://github.com/fralonra.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"corsen\n=======\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/corsen.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/corsen\n[travis-image]: https://img.shields.io/travis/fralonra/corsen.svg?style=flat-square\n[travis-url]: https://travis-ci.com/fralonra/corsen\n[download-image]: https://img.shields.io/npm/dm/corsen.svg?style=flat-square\n[download-url]: https://npmjs.org/package/corsen\n\nA universal [Cross-Origin Resource Sharing(CORS)](https://developer.mozilla.org/en/docs/Web/HTTP/Access_control_CORS) middleware. Derrived from [@koa/cors](https://github.com/koajs/cors).\n\n## Installation\n\n```bash\nnpm install corsen\n```\n\nor\n```bash\nyarn add corsen\n```\n\n## Quick start\n\nEnable cors with default options:\n\n- origin: request Origin header\n- allowMethods: GET,HEAD,PUT,POST,DELETE,PATCH\n\n```js\nconst http = require('http')\nconst cors = require('corsen')({\n  // place your options here\n})\n\nconst server = http.createServer((req, res) =\u003e {\n  cors(req, res)\n  // if you pass a function to options.origin and that function returns a Promise, you can use async/await: await cors(req, res)\n  res.writeHead(200, { 'Content-Type': 'text/plain' })\n  res.end('ok')\n})\n```\n\n## cors(options)\n\n```js\n/**\n * CORS middleware\n *\n * @param {Object} [options]\n *  - {String|Function(req, res)} origin `access-control-allow-origin`, default is 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} credentials `access-control-allow-credentials`\n * @return {Function} cors middleware\n * @api public\n */\n```\n\n## Credit\n\nAll the commit before [71c4d00](https://github.com/fralonra/corsen/commit/71c4d00b170f52fd1324e9fd028816408867f8a6) are credited to koajs contributors.\n\n## Difference between corsen and @koa/cors\n\n- The middleware function returned by `corsen` has a signature of `function(http.IncomingMessage, http.ServerResponse)`, while `@koa/cors` recieves a koa's `Context` object.\n- All the header names set in `corsen` are lowercase.\n- `corsen` has removed the error handling utility of `@koa/cors`. There is not `keepHeadersOnError` porperty in options.\n\n## Examples\n\n[felid-cors](https://github.com/felidjs/felid-cors) A [Felid](https://github.com/felidjs/felid) plugin for CORS.\n\n## License\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffralonra%2Fcorsen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffralonra%2Fcorsen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffralonra%2Fcorsen/lists"}