{"id":18535286,"url":"https://github.com/tinyhttp/cors","last_synced_at":"2025-04-09T15:32:01.628Z","repository":{"id":57166678,"uuid":"387835816","full_name":"tinyhttp/cors","owner":"tinyhttp","description":"🌐 CORS middleware for modern Node.js","archived":false,"fork":false,"pushed_at":"2024-07-12T15:17:19.000Z","size":220,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T08:46:52.092Z","etag":null,"topics":["cors","cors-middleware","http","middleware","nodejs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tinyhttp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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,"publiccode":null,"codemeta":null},"funding":{"github":["tinyhttp","talentlessguy"],"issuehunt":"talentlessguy"}},"created_at":"2021-07-20T15:29:17.000Z","updated_at":"2024-07-12T15:17:17.000Z","dependencies_parsed_at":"2022-08-30T15:21:33.720Z","dependency_job_id":"764c371d-0ebc-4450-8960-9156d0ac6a29","html_url":"https://github.com/tinyhttp/cors","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"tinyhttp/repo-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyhttp%2Fcors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyhttp%2Fcors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyhttp%2Fcors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyhttp%2Fcors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tinyhttp","download_url":"https://codeload.github.com/tinyhttp/cors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248058069,"owners_count":21040688,"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","cors-middleware","http","middleware","nodejs"],"created_at":"2024-11-06T19:21:47.259Z","updated_at":"2025-04-09T15:32:01.621Z","avatar_url":"https://github.com/tinyhttp.png","language":"TypeScript","readme":"\u003cdiv align=\"center\"\u003e\n\n# @tinyhttp/cors\n\n[![npm][npm-img]][npm-url] [![GitHub Workflow Status][gh-actions-img]][github-actions] [![Coverage][cov-img]][cov-url]\n\n\u003c/div\u003e\n\n\u003e A rewrite of [expressjs/cors](https://github.com/expressjs/cors) module.\n\nHTTP cors header middleware.\n\n## Install\n\n```sh\npnpm i @tinyhttp/cors\n```\n\n## API\n\n```ts\nimport { cors } from '@tinyhttp/cors'\n```\n\n### `cors(options)`\n\nReturns the CORS middleware with the settings specified in the parameters\n\n#### Options\n\n- `origin`: Can be a string defining the `Access-Control-Allow-Origin` value, a boolean which if set to true sets the header to `'*'`, a Regex type, an array (for multiple origins) or a function which contains the request and response as parameters and must return the value for the `Access-Control-Allow-Origin` header\n- `methods`: Array of method names which define the `Access-Control-Allow-Methods` header, default to all the most common methods (`GET`, `HEAD`, `PUT`, `PATCH`, `POST`, `DELETE`)\n- `allowedHeaders`: Configures the `Access-Control-Allow-Headers` CORS header. Expects an array (ex: [`'Content-Type'`, `'Authorization'`]).\n- `exposedHeaders`: Configures the `Access-Control-Expose-Headers` CORS header. If not specified, no custom headers are exposed\n- `credentials`: Configures the `Access-Control-Allow-Credentials` CORS header. Set to true to pass the header, otherwise it is omitted.\n- `maxAge`: Configures the `Access-Control-Max-Age` CORS header. Set to an integer to pass the header, otherwise it is omitted.\n- `optionsSuccessStatus`: Provides a status code to use for successful OPTIONS requests, since some legacy browsers (IE11, various SmartTVs) choke on 204.\n- `preflightContinue`: Set 204 and finish response if `true`, call `next` if false.\n\nThe default configuration is:\n\n```json\n{\n  \"origin\": \"*\",\n  \"methods\": [\"GET\", \"HEAD\", \"PUT\", \"PATCH\", \"POST\", \"DELETE\"],\n  \"optionsSuccessStatus\": 204,\n  \"preflightContinue\": false\n}\n```\n\n## Example\n\n```ts\nimport { App } from '@tinyhttp/app'\nimport { cors } from '@tinyhttp/cors'\n\nconst app = new App()\n\napp\n  .use(cors({ origin: 'https://myfantastic.site/' }))\n  .options('*', cors())\n  .get('/', (req, res) =\u003e {\n    res.send('The headers contained in my response are defined in the cors middleware')\n  })\n  .listen(3000)\n```\n\n[npm-url]: https://npmjs.com/package/@tinyhttp/cors\n[github-actions]: https://github.com/tinyhttp/cors/actions\n[gh-actions-img]: https://img.shields.io/github/actions/workflow/status/tinyhttp/cors/ci.yml?style=for-the-badge\u0026logo=github\u0026label=\u0026color=hotpink\n[cov-img]: https://img.shields.io/coveralls/github/tinyhttp/cors?style=for-the-badge\u0026color=hotpink\n[cov-url]: https://coveralls.io/github/tinyhttp/cors\n[npm-img]: https://img.shields.io/npm/dt/@tinyhttp/cors?style=for-the-badge\u0026color=hotpink\n","funding_links":["https://github.com/sponsors/tinyhttp","https://github.com/sponsors/talentlessguy","https://issuehunt.io/r/talentlessguy"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinyhttp%2Fcors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftinyhttp%2Fcors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinyhttp%2Fcors/lists"}