{"id":22489257,"url":"https://github.com/michealroberts/nitro-cors","last_synced_at":"2025-11-01T16:30:28.127Z","repository":{"id":169752926,"uuid":"645362937","full_name":"michealroberts/nitro-cors","owner":"michealroberts","description":"CORS event handler for the Nitro web server","archived":false,"fork":false,"pushed_at":"2024-04-12T13:24:12.000Z","size":74,"stargazers_count":16,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-13T17:54:04.027Z","etag":null,"topics":["cors","cors-middleware","cross-origin-resource-sharing","h3","nitro","nuxt","nuxt3"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/nitro-cors","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/michealroberts.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"publiccode":null,"codemeta":null}},"created_at":"2023-05-25T13:37:54.000Z","updated_at":"2024-04-13T17:54:04.028Z","dependencies_parsed_at":null,"dependency_job_id":"3d3e90a9-a0c0-4038-ad43-d7083dd95504","html_url":"https://github.com/michealroberts/nitro-cors","commit_stats":null,"previous_names":["michealroberts/nitro-cors"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michealroberts%2Fnitro-cors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michealroberts%2Fnitro-cors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michealroberts%2Fnitro-cors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michealroberts%2Fnitro-cors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michealroberts","download_url":"https://codeload.github.com/michealroberts/nitro-cors/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239301979,"owners_count":19616451,"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","cross-origin-resource-sharing","h3","nitro","nuxt","nuxt3"],"created_at":"2024-12-06T17:19:30.751Z","updated_at":"2025-11-01T16:30:28.095Z","avatar_url":"https://github.com/michealroberts.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# nitro Cross-Origin Resource Sharing (CORS) Headers\n\nnitro native CORS event handler.\n\n## Requirements\n\n- [nitro](https://nitro.unjs.io) v.2.6.\\* or higher\n\n## Installation\n\n```bash\nnpm install nitro-cors\n```\n\n```bash\npnpm add nitro-cors\n```\n\n```bash\nyarn add nitro-cors\n```\n\n## Usage\n\nnitro CORS is built upon the h3 CORS utilities provided by the h3 library. To read more about h3's inbuilt cors library, please consult the [h3 repository](https://github.com/unjs/h3#utilities).\n\nTo get started, you can enable CORS on a specific event handler by using the object syntax definitions intorduced in nitro v2.6.0 and h3 v1.8.0 as follows:\n\n```ts\nimport { cors } from 'nitro-cors'\n\nexport default eventHandler({\n  onRequest: [\n    cors({\n      origin: '*',\n      methods: '*'\n      // ... add your options overrides here\n    })\n  ],\n  async handler(event) {\n    return 'Hello CORS!'\n  }\n})\n```\n\nnitro-cors also provides a simple wrapper to define a CORS event handler per nitro event handler, or per route. To use it, simply import the `defineCORSEventHandler` function and wrap your event handler with it as follows:\n\n```ts\nimport { defineCORSEventHandler } from 'nitro-cors'\n\nconst handler = eventHandler(async event =\u003e {\n  // ...\n})\n\nexport default defineCORSEventHandler(handler, {\n  origin: '*',\n  methods: '*'\n})\n```\n\n...or... using as nitro middleware:\n\n```ts\n// :file middleware/cors.ts\nimport { corsEventHandler } from 'nitro-cors'\n\nexport default corsEventHandler(_event =\u003e {}, {\n  origin: '*',\n  methods: '*'\n})\n```\n\nThe `defineCORSEventHandler` and `corsEventHandler` functions take two arguments:\n\n- `handler`: the event handler to wrap of type `EventHandler\u003cT\u003e`, which will ensure typesafety for the event handler return type.\n- `options`: the options to pass to the cors handler of type `H3CorsOptions`. These are the same options as the ones passed to the h3 cors library.\n\n## Options\n\nThe options passed to the cors handler are the same as the ones passed to the h3 cors library. Please consult the [h3 repository](https://github.com/unjs/h3#utilities)\n\n## Acknowledgements\n\nThis library would not be possible if it were not for standing on the shoulders of these giants:\n\n- [h3](https://github.com/unjs)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichealroberts%2Fnitro-cors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichealroberts%2Fnitro-cors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichealroberts%2Fnitro-cors/lists"}