PHPackages                             papimod/cors - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. papimod/cors

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

papimod/cors
============

Module Papi

v2.1.0(4mo ago)00Apache-2.0PHPPHP &gt;=8.3.0

Since Dec 8Pushed 4mo agoCompare

[ Source](https://github.com/4uruanna/papimod-cors)[ Packagist](https://packagist.org/packages/papimod/cors)[ RSS](/packages/papimod-cors/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)Versions (6)Used By (0)

CORS Papi Module
================

[](#cors-papi-module)

[![](https://camo.githubusercontent.com/4893040bcf8e285d2895bb07a0985e48a3ddc545ff0abdeb11622706315de0f0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e352d3737374242343f6c6f676f3d706870)](https://camo.githubusercontent.com/4893040bcf8e285d2895bb07a0985e48a3ddc545ff0abdeb11622706315de0f0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e352d3737374242343f6c6f676f3d706870)[![](https://camo.githubusercontent.com/1a63c4971998a5b902b01583c76051a8ee8deec80235c1f6c8b5bd8e78725680/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f6d706f7365722d322d3838353633303f6c6f676f3d636f6d706f736572)](https://camo.githubusercontent.com/1a63c4971998a5b902b01583c76051a8ee8deec80235c1f6c8b5bd8e78725680/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f6d706f7365722d322d3838353633303f6c6f676f3d636f6d706f736572)

Description
-----------

[](#description)

Help setting up [cross-origin resource sharing](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS) in your [papi](https://github.com/4uruanna/papi).

This module is based on the [official tutorial](https://www.slimframework.com/docs/v4/cookbook/enable-cors.html).

Prerequisites Modules
---------------------

[](#prerequisites-modules)

- [Dotenv](https://github.com/4uruanna/papimod-dotenv)
- [Http Error](https://github.com/4uruanna/papimod-http-error)

Configuration
-------------

[](#configuration)

### `CORS_ORIGIN` (.ENV)

[](#cors_origin-env)

RequiredNoTypestringDescriptionSet *Access-Control-Allow-Origin*Default`*`### `CORS_METHODS` (.ENV)

[](#cors_methods-env)

RequiredNoTypestringDescriptionSet *Access-Control-Allow-Methods*Default`GET, POST, PUT, PATCH, DELETE, OPTIONS`### `CORS_MAX_AGE` (.ENV)

[](#cors_max_age-env)

RequiredNoTypestringDescriptionSet *Access-Control-Max-Age*Default3600### `CORS_HEADERS` (.ENV)

[](#cors_headers-env)

RequiredNoTypestringDescriptionSet *Access-Control-Allow-Headers*Default`*`### `CORS_EXPOSE_HEADERS` (.ENV)

[](#cors_expose_headers-env)

RequiredNoTypestringDescriptionSet *Access-Control-Expose-Headers*Default`*`Usage
-----

[](#usage)

You can add the following options to your `.env` file:

```
CORS_PRIORITY=1
CORS_ORIGIN=plop.fr
CORS_HEADERS="Content-Type, x-requested-with"
CORS_EXPOSE_HEADERS="Content-Encoding, Foo-Bar"
CORS_METHODS="GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD"
```

Import the module when creating your application:

```
require __DIR__ . "/../vendor/autoload.php";

use Papi\PapiBuilder;
use Papimod\Dotenv\DotEnvModule;
use Papimod\Common\CommonModule;
use Papimod\HttpError\HttpErrorModule;
use Papimod\Cors\CorsModule;
use function DI\create;

$builder = new PapiBuilder();

$builder
    ->setModule(
        DotEnvModule::class, # Prerequisite
        CommonModule::class, # Prerequisite of HttpErrorModule
        HttpErrorModule::class, # Prerequisite
        CorsModule::class
    )
    ->build()
    ->run();
```

MDN Recommendations
-------------------

[](#mdn-recommendations)

- The server must not specify the `*` wildcard for the `Access-Control-Allow-Origin` response-header value, but must instead specify an explicit origin; for example: `Access-Control-Allow-Origin: https://example.com`
- The server must not specify the `*` wildcard for the `Access-Control-Allow-Headers` response-header value, but must instead specify an explicit list of header names; for example, `Access-Control-Allow-Headers: X-PINGOTHER, Content-Type`
- The server must not specify the `*` wildcard for the `Access-Control-Allow-Methods` response-header value, but must instead specify an explicit list of method names; for example, `Access-Control-Allow-Methods: POST, GET`
- The server must not specify the `*` wildcard for the `Access-Control-Expose-Headers` response-header value, but must instead specify an explicit list of header names; for example, `Access-Control-Expose-Headers: Content-Encoding, Kuma-Revision`

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance74

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Total

4

Last Release

147d ago

Major Versions

v1.0.2 → v2.1.02025-12-22

### Community

Maintainers

![](https://www.gravatar.com/avatar/22fd4dcec379ce472b56c0f51528fa61ce156e5063756abcce648361770fc839?d=identicon)[4uruanna](/maintainers/4uruanna)

---

Top Contributors

[![4uruanna](https://avatars.githubusercontent.com/u/179627698?v=4)](https://github.com/4uruanna "4uruanna (14 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/papimod-cors/health.svg)

```
[![Health](https://phpackages.com/badges/papimod-cors/health.svg)](https://phpackages.com/packages/papimod-cors)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
