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.

v3.2.0(2mo ago)1756.4k↓10.7%31MITPHPPHP &gt;=8.2

Since Apr 26Pushed 2mo 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 2w ago

READMEChangelog (8)Dependencies (16)Versions (14)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

58

—

FairBetter than 98% of packages

Maintenance86

Actively maintained with recent releases

Popularity40

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 90.6% 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 ~170 days

Recently: every ~229 days

Total

12

Last Release

68d ago

Major Versions

v1.1.1 → v2.0.02023-01-05

2.x-dev → 3.2.x-dev2026-06-11

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

v2.0.0PHP &gt;= 7.3

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

v2.1.1PHP &gt;=8.0

3.2.x-devPHP &gt;=8.2

### 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 (29 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

[mineadmin/mineadmin

Quickly build a background management system for web applications

1.2k2.3k](/packages/mineadmin-mineadmin)[friendsofhyperf/sentry

The sentry component for Hyperf.

1977.7k](/packages/friendsofhyperf-sentry)[hyperf/websocket-server

A websocket server library for Hyperf.

12537.0k33](/packages/hyperf-websocket-server)[tangwei/dto

php hyperf dto

18140.5k3](/packages/tangwei-dto)

PHPackages © 2026

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