{"_id":"@captbunzo/elysia-cors","name":"@captbunzo/elysia-cors","dist-tags":{"latest":"1.4.1"},"versions":{"1.4.1":{"name":"@captbunzo/elysia-cors","version":"1.4.1","description":"Plugin for Elysia that for Cross Origin Requests (CORs) with async origin support","author":{"name":"captbunzo","email":"captbunzo@users.noreply.github.com","url":"https://github.com/captbunzo"},"repository":{"type":"git","url":"git+https://github.com/captbunzo/elysia-cors.git"},"main":"./dist/cjs/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{"./package.json":"./package.json",".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/cjs/index.js"}},"homepage":"https://github.com/captbunzo/elysia-cors","keywords":["elysia","cors"],"license":"MIT","scripts":{"dev":"bun run --watch example/index.ts","test":"bun test && npm run test:node","test:node":"npm install --prefix ./test/node/cjs/ && npm install --prefix ./test/node/esm/ && node ./test/node/cjs/index.js && node ./test/node/esm/index.js","build":"bun build.ts","release":"npm run build && npm run test && npm publish --access public"},"devDependencies":{"@types/bun":"1.1.14","@types/node":"^20.14.10","elysia":"1.4.0","eslint":"9.6.0","tsup":"^8.1.0","typescript":"^5.5.2"},"peerDependencies":{"elysia":">= 1.4.0"},"_id":"@captbunzo/elysia-cors@1.4.1","gitHead":"34ab57fc0fb1ac2793e8e4e18bfa0827aa1428c3","bugs":{"url":"https://github.com/captbunzo/elysia-cors/issues"},"_nodeVersion":"24.6.0","_npmVersion":"11.5.2","dist":{"integrity":"sha512-pHa+RS+BbUfdlX5aMG8sok7JUdp5s1uTG4p6J3JD0QrFA385W8K75oAjN2dqLlwrFg0NMtfv7zrgzRqlK3Ntig==","shasum":"0de259df5b802292d527dff7dd16c916d6a8483d","tarball":"https://registry.npmjs.org/@captbunzo/elysia-cors/-/elysia-cors-1.4.1.tgz","fileCount":10,"unpackedSize":79506,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIHIgxThoDUL6q1yALPtMrugXaOqoAKpzlc89hvZ6lCqOAiBwUc/A4rdaiCcbe0UW6m6P8w5uMvAKdJKyO6fWG+7mFw=="}]},"_npmUser":{"name":"captbunzo","email":"captbunzo@gmail.com"},"directories":{},"maintainers":[{"name":"captbunzo","email":"captbunzo@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/elysia-cors_1.4.1_1762109756102_0.7513932506735659"},"_hasShrinkwrap":false}},"time":{"created":"2025-11-02T18:55:56.008Z","1.4.1":"2025-11-02T18:55:56.293Z","modified":"2025-11-02T18:55:56.729Z"},"maintainers":[{"name":"captbunzo","email":"captbunzo@gmail.com"}],"description":"Plugin for Elysia that for Cross Origin Requests (CORs) with async origin support","homepage":"https://github.com/captbunzo/elysia-cors","keywords":["elysia","cors"],"repository":{"type":"git","url":"git+https://github.com/captbunzo/elysia-cors.git"},"author":{"name":"captbunzo","email":"captbunzo@users.noreply.github.com","url":"https://github.com/captbunzo"},"bugs":{"url":"https://github.com/captbunzo/elysia-cors/issues"},"license":"MIT","readme":"# @captbunzo/elysia-cors\nPlugin for [elysia](https://github.com/elysiajs/elysia) that for Cross Origin Requests (CORs) with async origin support\n\n**Fork Note**: This is a fork of the official @elysiajs/cors package that adds support for asynchronous origin functions. Once the [upstream PR #73](https://github.com/elysiajs/elysia-cors/pull/73) is merged, consider switching back to the official package.\n\n## Installation\n```bash\nbun add @captbunzo/elysia-cors\n```\n\n## Example\n```typescript\nimport { Elysia } from 'elysia'\nimport { cors } from '@captbunzo/elysia-cors'\n\nconst app = new Elysia()\n    .use(cors())\n    .listen(8080)\n```\n\n## Config\n### origin\n@default `true`\n\nAssign the **Access-Control-Allow-Origin** header.\n\nValue can be one of the following:\n- `string` - String of origin which will directly assign to `Access-Control-Allow-Origin`\n\n- `boolean` - If set to true, `Access-Control-Allow-Origin` will be set to `*` (accept all origin)\n\n- `RegExp` - Pattern to use to test with request's url, will accept origin if matched.\n\n- `Function` - Custom logic to validate origin acceptance or not. will accept origin if `true` is returned.\n    - Function will accepts `Context` just like `Handler`\n    ```typescript\n    // Example usage\n    app.use(cors, {\n        origin: ({ request, headers }) => true\n    })\n\n    // Type Definition\n    type CORSOriginFn = (context: Context) => boolean | void | Promise<boolean | void>\n    ```\n\n#### Async Origin Functions (New Feature)\nThis fork adds support for asynchronous origin validation functions. You can now perform database lookups, API calls, or other async operations to determine if an origin should be allowed:\n\n```typescript\napp.use(cors, {\n    origin: async ({ request }) => {\n        const origin = request.headers.get('origin')\n        // Example: Check with external service or database\n        const isAllowed = await checkOriginInDatabase(origin)\n        return isAllowed\n    }\n})\n```\n\n- `Array<string | RegExp | Function>` - Will try to find truthy value of all options above. Will accept Request if one is `true`.\n\n### methods\n@default `*`\n\nAssign **Access-Control-Allow-Methods** header. \n\nValue can be one of the following:\nAccept:\n- `undefined | null | ''` - Ignore all methods.\n\n- `*` - Accept all methods.\n\n- `HTTPMethod` - Will be directly set to **Access-Control-Allow-Methods**.\n    - Expects either a single method or a comma-delimited string (eg: 'GET, PUT, POST')\n\n- `HTTPMethod[]` - Allow multiple HTTP methods.\n    - eg: ['GET', 'PUT', 'POST']\n\n### allowedHeaders\n@default `*`\n\nAssign **Access-Control-Allow-Headers** header. \n\nAllow incoming request with the specified headers.\n\nValue can be one of the following:\n- `string`\n    - Expects either a single method or a comma-delimited string (eg: 'Content-Type, Authorization').\n\n- `string[]` - Allow multiple HTTP methods.\n    - eg: ['Content-Type', 'Authorization']\n\n### exposedHeaders\n@default `*`\n\nAssign **Access-Control-Exposed-Headers** header. \n\nReturn the specified headers to request in CORS mode.\n\nValue can be one of the following:\n- `string`\n    - Expects either a single method or a comma-delimited string (eg: 'Content-Type, 'X-Powered-By').\n\n- `string[]` - Allow multiple HTTP methods.\n    - eg: ['Content-Type', 'X-Powered-By']\n\n### credentials\n@default `true`\n\nAssign **Access-Control-Allow-Credentials** header. \n\nAllow incoming requests to send `credentials` header.\n\n- `boolean` - Available if set to `true`.\n\n### maxAge\n@default `5`\n\nAssign **Access-Control-Max-Age** header. \n\nAllow incoming requests to send `credentials` header.\n\n- `number` - Duration in seconds to indicates how long the results of a preflight request can be cached.\n\n### preflight\n@default `true`\n\nAdd `[OPTIONS] /*` handler to handle preflight request which response with `HTTP 204` and CORS hints.\n\n- `boolean` - Available if set to `true`.\n","readmeFilename":"README.md","_rev":"1-f93c20a529f8d629d189bf08da96fe75"}