{"id":15011420,"url":"https://github.com/cerebrusinc/buncors","last_synced_at":"2025-08-26T09:14:32.743Z","repository":{"id":203866767,"uuid":"710573739","full_name":"cerebrusinc/buncors","owner":"cerebrusinc","description":"A tool that brings expressjs cors functionality to bun's bunrest package.","archived":false,"fork":false,"pushed_at":"2023-10-28T14:00:52.000Z","size":15,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-25T04:57:57.822Z","etag":null,"topics":["bunjs","bunrest","cors","middleware"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/buncors","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cerebrusinc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-10-27T01:36:13.000Z","updated_at":"2025-03-03T17:27:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"3d10952c-b3e0-4163-8196-c797fa7007c8","html_url":"https://github.com/cerebrusinc/buncors","commit_stats":{"total_commits":10,"total_committers":1,"mean_commits":10.0,"dds":0.0,"last_synced_commit":"5786f92761e3a0f08c9ed059a7afb29db2d1c2a9"},"previous_names":["cerebrusinc/buncors"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cerebrusinc/buncors","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cerebrusinc%2Fbuncors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cerebrusinc%2Fbuncors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cerebrusinc%2Fbuncors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cerebrusinc%2Fbuncors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cerebrusinc","download_url":"https://codeload.github.com/cerebrusinc/buncors/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cerebrusinc%2Fbuncors/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272093013,"owners_count":24872081,"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","status":"online","status_checked_at":"2025-08-25T02:00:12.092Z","response_time":1107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["bunjs","bunrest","cors","middleware"],"created_at":"2024-09-24T19:41:04.554Z","updated_at":"2025-08-26T09:14:32.725Z","avatar_url":"https://github.com/cerebrusinc.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://drive.google.com/uc?id=1N3CW-z4Ekm69tR6sbcpw_InyUGnxz3wb\" alt=\"buncors logo\" width=\"250\" height=\"250\" /\u003e\n\u003c/p\u003e\n\n# buncors\n\nThe cors middleware that enables a [bunrest](https://www.npmjs.com/package/bunrest) server to handle cors requests. It also handles preflight requests 😃.\n\n## Default Response Headers\n\nIf no options are provided, the response headers will be as follows:\n\n```txt\nAccess-Control-Allow-Origin: *\nAccess-Control-Allow-Methods: GET,HEAD,PUT,PATCH,POST,DELETE\nAccess-Control-Allow-Headers: Content-Type\nAccess-Control-Max-Age: 5\n```\n\n**NOTE:** The allow headers will always append `Content-Type` to your response headers so no need to add it to the list.\n\n## Usage Examples\n\n**Globally**\n\n```ts\nimport server from \"bunrest\";\nimport cors from \"buncors\";\nconst app = server();\n\napp.use(cors());\n\napp.listen(Bun.env.PORT, () =\u003e {\n\tconsole.log(`[startup]: Server running on port \"${Bun.env.PORT}\"`);\n});\n```\n\n**Specific Route**\n\n```ts\nimport server from \"bunrest\";\nimport cors from \"buncors\";\nconst app = server();\n\napp.post(\"/auth\", cors(), async (req, res) =\u003e {\n\t// some processing code\n\tres.status(200).json({ success: true });\n});\n\napp.listen(Bun.env.PORT, () =\u003e {\n\tconsole.log(`[startup]: Server running on port \"${Bun.env.PORT}\"`);\n});\n```\n\n## Preflight Example\n\nNote that in most cases, you will not have to explicity handle a preflight request separately.\n\n```ts\nimport server from \"bunrest\";\nimport cors from \"buncors\";\nconst app = server();\n\napp.post(\"/auth\", async (req, res) =\u003e {\n\t// some processing code\n\tres.status(200).json({ success: true });\n});\n\napp.options(\n\t\"/auth\",\n\tcors({\n\t\tallowedHeaders: [\"X-TOKEN\"],\n\t\tmethods: [\"POST\"],\n\t\torigins: [\"www.cerebrus.dev\"],\n\t})\n);\n\napp.listen(Bun.env.PORT, () =\u003e {\n\tconsole.log(`[startup]: Server running on port \"${Bun.env.PORT}\"`);\n});\n```\n\n## CorsOptions Interface\n\n```ts\n\torigins?: string | string[];\n\tmethods?: string[];\n\tallowedHeaders?: string[];\n\tmaxAge?: number;\n\tallowCredentials?: boolean;\n\texposedHeaders?: string[];\n```\n\n| Param            | Type                          | Default                          | Is Required? | Description                                                                                                                               |\n| ---------------- | ----------------------------- | -------------------------------- | ------------ | ----------------------------------------------------------------------------------------------------------------------------------------- |\n| origins          | `string, string[], undefined` | `*`                              | No           | Sets the `Access-Control-Allow-Origin` header; if set, it will dynamically return the correct origin or the first origin is not accetped. |\n| methods          | `string[], undefined`         | `GET,HEAD,PUT,PATCH,POST,DELETE` | No           | Sets the `Access-Control-Allow-Methods` header.                                                                                           |\n| allowedHeaders   | `string[], undefined`         | `Content-Type`                   | No           | Sets the `Access-Control-Allow-Headers` header; will always append `Content-Type` to the allowed headers.                                 |\n| maxAge           | `number, undefined`           | `5`                              | No           | Sets the `Access-Control-Max-Age` header in **seconds**.                                                                                  |\n| allowCredentials | `boolean, undefined`          | `undefined`                      | No           | Sets the `Access-Control-Allow-Credentials` header.                                                                                       |\n| exposedHeaders   | `string[], undefined`         | `undefined`                      | No           | Sets the `Access-Control-Expose-Headers` header.                                                                                          |\n\n\u003cbr /\u003e\n\n# Changelog\n\n## v0.2.x\n\n\u003cdetails open\u003e\n\u003csummary\u003e\u003cstrong\u003ev0.2.3\u003c/strong\u003e\u003c/summary\u003e\n\n- Added gloabl decleration compatibility\n\u003c/details\u003e\n\u003cbr /\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003ev0.2.2\u003c/strong\u003e\u003c/summary\u003e\n\n- Better handling of wildcard origin\n\u003c/details\u003e\n\u003cbr /\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003ev0.2.1\u003c/strong\u003e\u003c/summary\u003e\n\n- Removed console log statement\n- Handling spaces in allowedHeaders request\n\u003c/details\u003e\n\u003cbr /\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003ev0.2.0\u003c/strong\u003e\u003c/summary\u003e\n\n- Updated handler to manage allowedHeaders regardless of ordering or case\n- Enabled non preflight requests returning headers EXCEPT allowedMethods\n- Now you can send exposed headers back to the client\n\u003c/details\u003e\n\u003cbr /\u003e\n\n## v0.1.x\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003ev0.1.2\u003c/strong\u003e\u003c/summary\u003e\n\n- Removed console log statement\n\u003c/details\u003e\n\u003cbr /\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003ev0.1.1\u003c/strong\u003e\u003c/summary\u003e\n\n- Added lib to NPM\n\u003c/details\u003e\n\u003cbr /\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003ev0.1.0\u003c/strong\u003e\u003c/summary\u003e\n\n- Initial commit\n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcerebrusinc%2Fbuncors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcerebrusinc%2Fbuncors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcerebrusinc%2Fbuncors/lists"}