PHPackages                             gokure/hyperf-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. gokure/hyperf-cors

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

gokure/hyperf-cors
==================

Adds CORS (Cross-Origin Resource Sharing) headers support in your Hyperf application.

v2.1.1(2y ago)1848.6k↓28.6%31MITPHPPHP &gt;=8.0

Since Apr 26Pushed 2y ago2 watchersCompare

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

READMEChangelog (7)Dependencies (8)Versions (12)Used By (1)

CORS Middleware for Hyperf
==========================

[](#cors-middleware-for-hyperf)

[![Build Status](https://github.com/gokure/hyperf-cors/actions/workflows/tests.yml/badge.svg)](https://github.com/gokure/hyperf-cors/actions)[![Latest Stable Version](https://camo.githubusercontent.com/9aa1c0eb492e8d8b0f035d1075f2f575be22fcb37041fa6a21fd4a7238ae7f11/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f676f6b7572652f6879706572662d636f72732e737667)](https://packagist.org/packages/gokure/hyperf-cors)[![Total Downloads](https://camo.githubusercontent.com/5228dcdb91e4f9bd403eb099c16bc3ba28fc519e43015d677b8f5a8776cb6730/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f676f6b7572652f6879706572662d636f72732e737667)](https://packagist.org/packages/gokure/hyperf-cors)[![GitHub license](https://camo.githubusercontent.com/272df803a1e5ca0423e5a756ec958a044f2ec53664a79c0491c08c369c9191bb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f676f6b7572652f6879706572662d636f7273)](LICENSE)

Implements [fruitcake/laravel-cors](https://github.com/fruitcake/laravel-cors) for Hyperf.

Features
--------

[](#features)

- Handles CORS pre-flight OPTIONS requests
- Adds CORS headers to your responses
- Match routes to only add CORS to certain Requests

Installation
------------

[](#installation)

Require the `gokure/hyperf-cors` package in your `composer.json` and update your dependencies:

```
composer require gokure/hyperf-cors
```

Global usage
------------

[](#global-usage)

To allow CORS for all your routes, add the `CorsMiddleware` middleware at the top of the property of `config/autoload/middlewares.php` file and set the `paths` property in the config (see Configuration below):

```
'http' => [
    \Gokure\HyperfCors\CorsMiddleware::class,
    ...
],
```

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

[](#configuration)

The defaults are set in `config/autoload/cors.php`. Publish the config to copy the file to your own config:

```
php bin/hyperf.php vendor:publish gokure/hyperf-cors
```

> **Note:** When using custom headers, like `X-Auth-Token` or `X-Requested-With`, you must set the `allowed_headers` to include those headers. You can also set it to `['*']` to allow all custom headers.

> **Note:** If you are explicitly whitelisting headers, you must include `Origin` or requests will fail to be recognized as CORS.

### Options

[](#options)

OptionDescriptionDefault valuepathsYou can enable CORS for 1 or multiple paths, eg. `['api/*'] ``[]`allowed\_originsMatches the request origin. Wildcards can be used, eg. `*.mydomain.com` or `mydomain.com:*``['*']`allowed\_origins\_patternsMatches the request origin with `preg_match`.`[]`allowed\_methodsMatches the request method.`['*']`allowed\_headersSets the Access-Control-Allow-Headers response header.`['*']`exposed\_headersSets the Access-Control-Expose-Headers response header.`false`max\_ageSets the Access-Control-Max-Age response header.`0`supports\_credentialsSets the Access-Control-Allow-Credentials header.`false``allowed_origins`, `allowed_headers` and `allowed_methods` can be set to `['*']` to accept any value.

> **Note:** For `allowed_origins` you must include the scheme when not using a wildcard, e.g. `['http://example.com', 'https://example.com']`. You must also take into account that the scheme will be present when using `allowed_origins_patterns`.

License
-------

[](#license)

Released under the MIT License, see [LICENSE](LICENSE).

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 90% 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 ~106 days

Recently: every ~162 days

Total

10

Last Release

889d ago

Major Versions

v1.1.1 → v2.0.02023-01-05

PHP version history (4 changes)v1.0.0PHP &gt;= 7.2

v2.0.0PHP &gt;= 7.3

v2.1.0PHP &gt;= 7.3|&gt;= 8.0

2.x-devPHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/d2db6a5e19964c28865f3c11a012d8b7d68cd38e96c2f4faf7411a83b1f469ae?d=identicon)[gokure](/maintainers/gokure)

---

Top Contributors

[![gokure](https://avatars.githubusercontent.com/u/88591?v=4)](https://github.com/gokure "gokure (27 commits)")[![alexsyvolap](https://avatars.githubusercontent.com/u/80973788?v=4)](https://github.com/alexsyvolap "alexsyvolap (2 commits)")[![girorme](https://avatars.githubusercontent.com/u/54730507?v=4)](https://github.com/girorme "girorme (1 commits)")

---

Tags

corshyperf

###  Code Quality

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[asm89/stack-cors

Cross-origin resource sharing library and stack middleware

1.3k180.6M24](/packages/asm89-stack-cors)[fruitcake/php-cors

Cross-origin resource sharing library for the Symfony HttpFoundation

314242.1M35](/packages/fruitcake-php-cors)[tuupola/cors-middleware

PSR-7 and PSR-15 CORS middleware

1331.8M24](/packages/tuupola-cors-middleware)[neomerx/cors-psr7

Framework agnostic (PSR-7) CORS implementation (www.w3.org/TR/cors/)

682.4M19](/packages/neomerx-cors-psr7)[jdesrosiers/silex-cors-provider

A silex service provider that adds CORS services to silex

83892.3k10](/packages/jdesrosiers-silex-cors-provider)[hyperf/websocket-server

A websocket server library for Hyperf.

12488.7k25](/packages/hyperf-websocket-server)

PHPackages © 2026

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