{"id":19458830,"url":"https://github.com/leafsphp/cors","last_synced_at":"2025-08-23T02:32:59.708Z","repository":{"id":49355900,"uuid":"409296683","full_name":"leafsphp/cors","owner":"leafsphp","description":"🔖 CORS module for leaf + PHP","archived":false,"fork":false,"pushed_at":"2024-09-29T18:43:44.000Z","size":14,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-06T10:40:04.500Z","etag":null,"topics":["cors","leafphp","php"],"latest_commit_sha":null,"homepage":"https://leafphp.dev/modules/cors/","language":"PHP","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/leafsphp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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,"zenodo":null},"funding":{"open_collective":"leaf","github":"leafsphp"}},"created_at":"2021-09-22T17:29:23.000Z","updated_at":"2024-09-27T17:53:39.000Z","dependencies_parsed_at":"2025-04-30T18:40:37.376Z","dependency_job_id":null,"html_url":"https://github.com/leafsphp/cors","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/leafsphp/cors","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafsphp%2Fcors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafsphp%2Fcors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafsphp%2Fcors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafsphp%2Fcors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leafsphp","download_url":"https://codeload.github.com/leafsphp/cors/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafsphp%2Fcors/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271732385,"owners_count":24811312,"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-23T02:00:09.327Z","response_time":69,"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":["cors","leafphp","php"],"created_at":"2024-11-10T17:28:40.700Z","updated_at":"2025-08-23T02:32:59.596Z","avatar_url":"https://github.com/leafsphp.png","language":"PHP","readme":"\u003c!-- markdownlint-disable no-inline-html --\u003e\n\u003cp align=\"center\"\u003e\n  \u003cbr\u003e\u003cbr\u003e\n  \u003cimg src=\"https://leafphp.netlify.app/assets/img/leaf3-logo.png\" height=\"100\"/\u003e\n  \u003ch1 align=\"center\"\u003eLeaf Cors Module\u003c/h1\u003e\n  \u003cbr\u003e\u003cbr\u003e\n\u003c/p\u003e\n\n# Leaf PHP\n\n[![Latest Stable Version](https://poser.pugx.org/leafs/cors/v/stable)](https://packagist.org/packages/leafs/cors)\n[![Total Downloads](https://poser.pugx.org/leafs/cors/downloads)](https://packagist.org/packages/leafs/cors)\n[![License](https://poser.pugx.org/leafs/cors/license)](https://packagist.org/packages/leafs/cors)\n\nThis is the CORS handler for Leaf.\n\n## Installation\n\nYou can easily install it using [leaf cli](https://cli.leafphp.dev)\n\n```sh\nleaf install cors\n```\n\nor with [Composer](https://getcomposer.org/):\n\n```bash\ncomposer require leafs/cors\n```\n\n## Usage\n\nAfter installing the cors module, the cors module is automatically linked to the leaf app and can be used directly without referencing it anywhere.\n\n### Simple Usage (Enable *All* CORS Requests)\n\n```php\nrequire __DIR__ . \"/vendor/autoload.php\";\n\n$app = new Leaf\\App;\n\n$app-\u003ecors();\n\n$app-\u003eget('/products/{id}', function () use($app) {\n  $app-\u003eresponse()-\u003ejson(['message' =\u003e 'This is CORS-enabled for all origins!']);\n});\n\n$app-\u003erun();\n```\n\nYou can alternatively call `Leaf\\Http\\Cors::config()` instead of `$app-\u003ecors()` in the example above.\n\n### Configuring CORS\n\n```php\nrequire __DIR__ . '/vendor/autoload.php';\n\n$app = new Leaf\\App;\n\n$app-\u003ecors([\n  'origin' =\u003e 'http://example.com',\n  'optionsSuccessStatus' =\u003e 200 // some legacy browsers (IE11, various SmartTVs) choke on 204\n]);\n\n$app-\u003eget('/products/{id}', function () use($app) {\n  $app-\u003eresponse()-\u003ejson(['message' =\u003e 'This is CORS-enabled for all origins!']);\n});\n\n$app-\u003erun();\n```\n\n## Configuration Options\n\n* `origin`: Configures the **Access-Control-Allow-Origin** CORS header. Possible values:\n  * `String` - set `origin` to a specific origin. For example if you set it to `\"http://example.com\"` only requests from \"http://example.com\" will be allowed.\n  * `RegExp (in string form)` - set `origin` to a regular expression pattern which will be used to test the request origin. If it's a match, the request origin will be reflected. For example the pattern `'/example\\.com$/'` will reflect any request that is coming from an origin ending with \"example.com\".\n  * `Array` - set `origin` to an array of valid origins. Each origin can be a `String` or a `RegExp`. For example `[\"http://example1.com\", '/\\.example2\\.com$/']` will accept any request from \"http://example1.com\" or from a subdomain of \"example2.com\".\n  * `Function` - set `origin` to a function implementing some custom logic. The function takes the request origin as the first parameter and a callback (called as `callback(err, origin)`, where `origin` is a non-function value of the `origin` option) as the second.\n* `methods`: Configures the **Access-Control-Allow-Methods** CORS header. Expects a comma-delimited string (ex: 'GET,PUT,POST') or an array (ex: `['GET', 'PUT', 'POST']`).\n* `allowedHeaders`: Configures the **Access-Control-Allow-Headers** CORS header. Expects a comma-delimited string (ex: 'Content-Type,Authorization') or an array (ex: `['Content-Type', 'Authorization']`). If not specified, defaults to reflecting the headers specified in the request's **Access-Control-Request-Headers** header.\n* `exposedHeaders`: Configures the **Access-Control-Expose-Headers** CORS header. Expects a comma-delimited string (ex: 'Content-Range,X-Content-Range') or an array (ex: `['Content-Range', 'X-Content-Range']`). 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* `preflightContinue`: Pass the CORS preflight response to the next handler.\n* `optionsSuccessStatus`: Provides a status code to use for successful `OPTIONS` requests, since some legacy browsers (IE11, various SmartTVs) choke on `204`.\n\nThe default configuration is the equivalent of:\n\n```json\n{\n  \"origin\": \"*\",\n  \"methods\": \"GET,HEAD,PUT,PATCH,POST,DELETE\",\n  \"allowedHeaders\": \"*\",\n  \"exposedHeaders\": \"\",\n  \"credentials\": false,\n  \"maxAge\": null,\n  \"preflightContinue\": false,\n  \"optionsSuccessStatus\": 204,\n}\n```\n","funding_links":["https://opencollective.com/leaf","https://github.com/sponsors/leafsphp"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleafsphp%2Fcors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleafsphp%2Fcors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleafsphp%2Fcors/lists"}