{"id":14987320,"url":"https://github.com/agungsugiarto/codeigniter4-cors","last_synced_at":"2025-08-21T23:23:04.103Z","repository":{"id":44448474,"uuid":"284404727","full_name":"agungsugiarto/codeigniter4-cors","owner":"agungsugiarto","description":"The codeigniter4-cors package allows you to send Cross-Origin Resource Sharing headers with Codeigniter4 filter configuration.","archived":false,"fork":false,"pushed_at":"2023-06-29T13:55:08.000Z","size":36,"stargazers_count":65,"open_issues_count":3,"forks_count":14,"subscribers_count":4,"default_branch":"3.x","last_synced_at":"2025-06-15T20:49:07.469Z","etag":null,"topics":["codeigniter4","codeigniter4-library","cors"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/agungsugiarto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","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},"funding":{"custom":"https://saweria.co/agungsugiarto"}},"created_at":"2020-08-02T06:26:05.000Z","updated_at":"2025-06-11T18:35:18.000Z","dependencies_parsed_at":"2024-06-18T21:30:03.223Z","dependency_job_id":null,"html_url":"https://github.com/agungsugiarto/codeigniter4-cors","commit_stats":{"total_commits":27,"total_committers":1,"mean_commits":27.0,"dds":0.0,"last_synced_commit":"4b7ed2d0f6dfd6f84983b8e7f2afc99a34e54607"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/agungsugiarto/codeigniter4-cors","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agungsugiarto%2Fcodeigniter4-cors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agungsugiarto%2Fcodeigniter4-cors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agungsugiarto%2Fcodeigniter4-cors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agungsugiarto%2Fcodeigniter4-cors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/agungsugiarto","download_url":"https://codeload.github.com/agungsugiarto/codeigniter4-cors/tar.gz/refs/heads/3.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agungsugiarto%2Fcodeigniter4-cors/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271156192,"owners_count":24708901,"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-19T02:00:09.176Z","response_time":63,"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":["codeigniter4","codeigniter4-library","cors"],"created_at":"2024-09-24T14:14:26.788Z","updated_at":"2025-08-20T07:30:57.821Z","avatar_url":"https://github.com/agungsugiarto.png","language":"PHP","funding_links":["https://saweria.co/agungsugiarto"],"categories":[],"sub_categories":[],"readme":"# CORS Filter for CodeIgniter 4\n\nInspired from https://github.com/asm89/stack-cors for CodeIgniter 4\n\n[![Latest Stable Version](https://poser.pugx.org/agungsugiarto/codeigniter4-cors/v)](https://packagist.org/packages/agungsugiarto/codeigniter4-cors)\n[![Total Downloads](https://poser.pugx.org/agungsugiarto/codeigniter4-cors/downloads)](https://packagist.org/packages/agungsugiarto/codeigniter4-cors)\n[![Latest Unstable Version](https://poser.pugx.org/agungsugiarto/codeigniter4-cors/v/unstable)](https://packagist.org/packages/agungsugiarto/codeigniter4-cors)\n[![License](https://poser.pugx.org/agungsugiarto/codeigniter4-cors/license)](https://packagist.org/packages/agungsugiarto/codeigniter4-cors)\n\n## **About**\n\nThe `codeigniter4-cors` package allows you to send [Cross-Origin Resource Sharing](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/)\nheaders with Codeigniter4 filter configuration.\n\n## **Features**\n\n* Handles CORS pre-flight OPTIONS requests\n* Adds CORS headers to your responses\n* Match routes to only add CORS to certain Requests\n\n## **Upgrade from 2.x to v3.x**\n\nUpgrade from version 2.x to 3.x. Open your `composer.json` find `agungsugiarto/codeigniter4-cors` and change value to `^3.0`\n\n## **Installation**\n\nRequire the `agungsugiarto/codeigniter4-cors` package in your `composer.json` and update your dependencies:\n```sh\ncomposer require agungsugiarto/codeigniter4-cors\n```\n\n## **Global usage**\n\nTo allow CORS for all your routes, first register `CorsFilter.php` filter at the top of the `$aliases` property of  `App/Config/Filter.php` class:\n\n```php\npublic $aliases = [\n    'cors' =\u003e \\Fluent\\Cors\\Filters\\CorsFilter::class,\n    // ...\n];\n```\n\n### **Global restrictions**\nRestrict routes based on their URI pattern by editing **app/Config/Filters.php** and adding them to the\n`$filters` array, e.g.:\n\n```php\npublic $filters = [\n    // ...\n    'cors' =\u003e [\n        'before' =\u003e ['api/*'],\n        'after' =\u003e ['api/*']\n    ],\n];\n```\n\n### **Restricting a single route**\nAny single route can be restricted by adding the filter option to the last parameter in any of the route definition methods:\n```php\n$routes-\u003eget('api/users', 'UserController::index', ['filter' =\u003e 'cors']);\n```\n\n### **Restricting Route Groups**\nIn the same way, entire groups of routes can be restricted within the `group()` method:\n```php\n$routes-\u003egroup('api/v1', ['filter' =\u003e 'cors'], function ($routes) {\n    // ...\n});\n```\n\n## **Configuration**\n\nThe defaults are set in `config/cors.php`. Publish the config to copy the file to your own config:\n```sh\nphp spark cors:publish\n```\n\u003e **Note:** When using custom headers, like `X-Auth-Token` or `X-Requested-With`, you must set the `allowedHeaders` to include those headers. You can also set it to `['*']` to allow all custom headers.\n\n\u003e **Note:** If you are explicitly whitelisting headers, you must include `Origin` or requests will fail to be recognized as CORS.\n\n\n### **Options**\n\n| Option                   | Description                                                              | Default value |\n|--------------------------|--------------------------------------------------------------------------|---------------|\n| allowedOrigins           | Matches the request origin. Wildcards can be used, eg. `*.mydomain.com`  |    `['*']`    |\n| allowedOriginsPatterns   | Matches the request origin with preg_match.                              |    `[]`    |\n| allowedMethods           | Matches the request method.                                              |    `['*']`    |\n| allowedHeaders           | Sets the Access-Control-Allow-Headers response header.                   |    `['*']`    |\n| exposedHeaders           | Sets the Access-Control-Expose-Headers response header.                  |    `false`    |\n| maxAge                   | Sets the Access-Control-Max-Age response header.                         |    `0`        |\n| supportsCredentials      | Sets the Access-Control-Allow-Credentials header.                        |    `false`    |\n\n\n`allowedOrigins`, `allowedHeaders` and `allowedMethods` can be set to `['*']` to accept any value.\n\n\u003e **Note:** For `allowedOrigins` you must include the scheme when not using a wildcard, eg. `['http://example.com', 'https://example.com']`. You must also take into account that the scheme will be present when using allowed_origins_patterns.\n\n\u003e **Note:** Try to be a specific as possible. You can start developing with loose constraints, but it's better to be as strict as possible!\n\n## **License**\n\nReleased under the MIT License, see [LICENSE](https://github.com/agungsugiarto/codeigniter4-cors/blob/master/LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagungsugiarto%2Fcodeigniter4-cors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fagungsugiarto%2Fcodeigniter4-cors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagungsugiarto%2Fcodeigniter4-cors/lists"}