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

ActiveLibrary

gfacility/stack-cors
====================

Cross-origin resource sharing library and stack middleware

v2.0.12(3y ago)01.4kMITPHPPHP ^7.0|^8.0

Since Aug 14Pushed 3y agoCompare

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

READMEChangelogDependencies (4)Versions (30)Used By (0)

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

[](#stackcors)

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 `asm89/stack-cors` using composer.

Usage
-----

[](#usage)

This package can be used as a library or as [stack middleware](http://stackphp.com/).

### Options

[](#options)

OptionDescriptionDefault valueallowedMethodsMatches the request method.`[]`allowedOriginsMatches the request origin.`[]`allowedOriginsPatternsMatches the request origin with `preg_match`.`[]`allowedHeadersSets the Access-Control-Allow-Headers response header.`[]`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 `['*']` is provided to *allowedMethods*, *allowedOrigins* or *allowedHeaders* all methods / origins / headers are allowed.

### Example: using the library

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

```
