{"id":22030954,"url":"https://github.com/ts-stack/cors","last_synced_at":"2026-04-08T21:31:35.116Z","repository":{"id":60673183,"uuid":"544162622","full_name":"ts-stack/cors","owner":"ts-stack","description":null,"archived":false,"fork":false,"pushed_at":"2024-03-16T18:56:14.000Z","size":270,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-24T10:01:25.911Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/ts-stack.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.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,"publiccode":null,"codemeta":null}},"created_at":"2022-10-01T20:09:37.000Z","updated_at":"2022-10-02T13:16:53.000Z","dependencies_parsed_at":"2024-11-18T01:47:08.062Z","dependency_job_id":null,"html_url":"https://github.com/ts-stack/cors","commit_stats":{"total_commits":50,"total_committers":1,"mean_commits":50.0,"dds":0.0,"last_synced_commit":"ca36acfb9fdb0b5c8c0685bc64947ffa56f37c0d"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":"ts-stack/starter","purl":"pkg:github/ts-stack/cors","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ts-stack%2Fcors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ts-stack%2Fcors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ts-stack%2Fcors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ts-stack%2Fcors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ts-stack","download_url":"https://codeload.github.com/ts-stack/cors/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ts-stack%2Fcors/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31575435,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"ssl_error","status_checked_at":"2026-04-08T14:31:17.202Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-11-30T08:12:37.355Z","updated_at":"2026-04-08T21:31:35.097Z","avatar_url":"https://github.com/ts-stack.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @ts-stack/cors\n\nCORS is a node.js package writen in TypeScript for providing a sync middleware that can be used to enable [CORS](http://en.wikipedia.org/wiki/Cross-origin_resource_sharing) with various options.\n\nThis package is a fork of express/cors module from [this state](https://github.com/expressjs/cors/tree/f038e772283).\n\n* [Installation](#installation)\n* [Usage](#usage)\n  * [Simple Usage](#simple-usage-enable-all-cors-requests)\n  * [Enabling CORS Pre-Flight](#enabling-cors-pre-flight)\n\n## Installation\n\n```bash\nnpm install @ts-stack/cors\n```\n\n## Usage\n\n### Simple Usage (Enable CORS Requests to https://example.com)\n\n```js\nimport http from 'http';\nimport { cors, mergeOptions } from '@ts-stack/cors';\n\nconst hostname = '127.0.0.1';\nconst port = 3000;\nconst corsOptions = mergeOptions({ origin: 'https://example.com' });\n\nconst server = http.createServer((req, res) =\u003e {\n  res.statusCode = 200;\n  const headersSent = cors(req, res, corsOptions);\n  if (headersSent) {\n    return;\n  }\n  res.setHeader('Content-Type', 'text/plain');\n  res.end('This is CORS-enabled for https://example.com!');\n});\n\nserver.listen(port, hostname, () =\u003e {\n  console.log(`Server running at http://${hostname}:${port}/`);\n});\n```\n\n### Enabling CORS Preflight\n\nCertain CORS requests are considered 'complex' and require an initial `OPTIONS` request (called the [preflight request][1]). An example of a 'complex' CORS request is one that uses an HTTP verb other than GET/HEAD/POST (such as DELETE) or that uses custom headers. To enable preflighting, you must add a new OPTIONS handler for the route you want to support.\n\n# The default configuration\n\nThe default configuration is the equivalent of:\n\n```json\n{\n  \"origin\": \"*\",\n  \"allowedMethods\": \"GET,HEAD,PUT,PATCH,POST,DELETE\",\n  \"preflightContinue\": false,\n  \"optionsSuccessStatus\": 204\n}\n```\n\nFor details on the effect of each CORS header, read [this article on web.dev][2].\n\n\n[1]: https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request\n[2]: https://web.dev/cross-origin-resource-sharing/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fts-stack%2Fcors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fts-stack%2Fcors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fts-stack%2Fcors/lists"}