PHPackages                             makise-co/stack-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. makise-co/stack-cors

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

makise-co/stack-cors
====================

Cross-origin resource sharing library and stack middleware

v2.0.7(4y ago)0274MITPHPPHP &gt;=7.4

Since Apr 21Pushed 4y agoCompare

[ Source](https://github.com/makise-co/stack-cors)[ Packagist](https://packagist.org/packages/makise-co/stack-cors)[ Docs](https://github.com/makise-co/stack-cors)[ RSS](/packages/makise-co-stack-cors/feed)WikiDiscussions master Synced today

READMEChangelog (5)Dependencies (5)Versions (6)Used By (0)

Stack/Cors
==========

[](#stackcors)

Fork of  that allows to use original package in the Makise Framework.

Library and middleware enabling cross-origin resource sharing for your http-{foundation,kernel} using application. It attempts to implement the [W3C Recommendation](http://www.w3.org/TR/cors/) for cross-origin resource sharing.

Build status: [![.github/workflows/run-tests.yml](https://github.com/asm89/stack-cors/workflows/.github/workflows/run-tests.yml/badge.svg)](https://github.com/asm89/stack-cors/workflows/.github/workflows/run-tests.yml/badge.svg)

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

[](#installation)

Require `makise-co/stack-cors` using composer.

Usage
-----

[](#usage)

- Create `cors.php` config in your config directory
- Add `CorsServiceProvider` to the `config/app.php` "providers" section
- Add `CorsMiddleware` to the `config/http.php` "middleware" section

### Options

[](#options)

OptionDescriptionDefault valueallowedMethodsMatches the request method.`array()`allowedOriginsMatches the request origin.`array()`allowedOriginsPatternsMatches the request origin with `preg_match`.`array()`allowedHeadersSets the Access-Control-Allow-Headers response header.`array()`exposedHeadersSets the Access-Control-Expose-Headers response header.`false`maxAgeSets the Access-Control-Max-Age response header.`false`supportsCredentialsSets the Access-Control-Allow-Credentials header.`false`The *allowedMethods* and *allowedHeaders* options are case-insensitive.

You don't need to provide both *allowedOrigins* and *allowedOriginsPatterns*. If one of the strings passed matches, it is considered a valid origin.

If `array('*')` is provided to *allowedMethods*, *allowedOrigins* or *allowedHeaders* all methods / origins / headers are allowed.

### Example: config that allows CORS on all paths

[](#example-config-that-allows-cors-on-all-paths)

```
return [

    /*
     * You can enable CORS for 1 or multiple paths.
     * Example: ['api/*']
     */
    'paths' => ['*'],

    /*
    * Matches the request method. `[*]` allows all methods.
    */
    'allowedMethods' => ['*'],

    /*
     * Matches the request origin. `[*]` allows all origins.
     */
    'allowedOrigins' => ['*'],

    /*
     * Matches the request origin with, similar to `Request::is()`
     */
    'allowedOriginsPatterns' => [],

    /*
     * Sets the Access-Control-Allow-Headers response header. `[*]` allows all headers.
     */
    'allowedHeaders' => ['*'],

    /*
     * Sets the Access-Control-Expose-Headers response header.
     */
    'exposedHeaders' => false,

    /*
     * Sets the Access-Control-Max-Age response header.
     */
    'maxAge' => 600,

    /*
     * Sets the Access-Control-Allow-Credentials header.
     */
    'supportsCredentials' => true,

];
```

### Example: using the library

[](#example-using-the-library)

```
