PHPackages                             lithemod/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. [HTTP &amp; Networking](/categories/http)
4. /
5. lithemod/cors

ActiveLibrary[HTTP &amp; Networking](/categories/http)

lithemod/cors
=============

Configures Cross-Origin Resource Sharing (CORS) headers for your Lithe application.

v1.0.0(1y ago)28MITPHPPHP ^8.0

Since Oct 2Pushed 1y agoCompare

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

READMEChangelogDependencies (2)Versions (2)Used By (0)

CORS
====

[](#cors)

The CORS (Cross-Origin Resource Sharing) middleware in Lithe configures CORS headers to allow or restrict access to resources from different origins.

---

Installing the CORS Module
--------------------------

[](#installing-the-cors-module)

To use the CORS middleware in your Lithe project, you need to install the `lithemod/cors` package. Follow the steps below:

1. **Make sure you have Composer installed**. Composer is a dependency management tool for PHP.
2. **Open your terminal** and navigate to your Lithe project directory.
3. **Run the following command to install the module**:

    ```
    composer require lithemod/cors
    ```

    This will download and install the CORS module in your project, as well as automatically register any necessary dependencies.

Using the CORS Middleware
-------------------------

[](#using-the-cors-middleware)

The CORS middleware in Lithe is responsible for configuring Cross-Origin Resource Sharing headers, allowing or restricting access to your application's resources from different origins. To configure it in your application, add it using the `use()` method:

```
use Lithe\Middleware\Configuration\cors;

$app->use(cors());
```

### Configuring the CORS Middleware

[](#configuring-the-cors-middleware)

The CORS middleware can be configured with the following parameters:

- **origins**: Allowed origin(s) for accessing your resources. It can be a string or an array of strings. The default is `'*'` (any origin).
- **methods**: Allowed HTTP methods. The default is `'GET, POST, OPTIONS'`.
- **headers**: Allowed headers. It can be a string or an array of strings. The default is `'Origin, X-Requested-With, Content-Type, Accept'`.
- **credentials**: Indicates if credentials (such as cookies or authorization headers) are allowed. The default is `true`.
- **maxAge**: Time in seconds for caching the results of a preflight request. The default is `null`.

### Example Configuration:

[](#example-configuration)

```
$app->use(cors([
    'origins' => ['https://example.com', 'https://another.com'],
    'methods' => 'GET, POST, PUT, DELETE, OPTIONS',
    'headers' => ['Content-Type', 'Authorization'],
    'credentials' => true,
    'maxAge' => 86400,
]));
```

### Middleware Behavior

[](#middleware-behavior)

- **Allowed Origins**: The middleware sets the `Access-Control-Allow-Origin` header with the allowed origins.
- **Allowed Methods**: Sets the `Access-Control-Allow-Methods` header with the permitted HTTP methods.
- **Allowed Headers**: Sets the `Access-Control-Allow-Headers` header with the allowed headers.
- **Credentials**: Sets the `Access-Control-Allow-Credentials` header to allow credentials if configured as `true`.
- **Cache Duration**: Sets the `Access-Control-Max-Age` header to specify the duration for caching preflight requests.
- **Handling OPTIONS Requests**: The middleware handles OPTIONS (preflight) requests by returning a 200 OK status and terminating the response.

Considerations
--------------

[](#considerations)

- **Specific Origins**: If you specify concrete origins, only those origins will be able to access your resources.
- **HTTP Methods and Headers**: Configure the methods and headers according to your application's needs to ensure security and compatibility.
- **Preflight Requests**: The middleware ensures that OPTIONS requests are handled properly to support preflight requests.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

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

Unknown

Total

1

Last Release

584d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/56173de3a7bf7099dd8168efd730d3c2fb5df5174a123fdc37cee8c3589e2345?d=identicon)[williamhumbwavali](/maintainers/williamhumbwavali)

---

Top Contributors

[![williamhumbwavali](https://avatars.githubusercontent.com/u/127023095?v=4)](https://github.com/williamhumbwavali "williamhumbwavali (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M317](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M292](/packages/pusher-pusher-php-server)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)

PHPackages © 2026

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