Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/middlewares/cors
PSR-15 middleware to implement Cross-Origin Resource Sharing (CORS)
https://github.com/middlewares/cors
cors http middleware psr-15
Last synced: about 1 month ago
JSON representation
PSR-15 middleware to implement Cross-Origin Resource Sharing (CORS)
- Host: GitHub
- URL: https://github.com/middlewares/cors
- Owner: middlewares
- License: mit
- Created: 2016-10-09T09:59:04.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2022-10-27T15:24:01.000Z (about 2 years ago)
- Last Synced: 2024-10-23T16:38:49.702Z (about 2 months ago)
- Topics: cors, http, middleware, psr-15
- Language: PHP
- Size: 39.1 KB
- Stars: 12
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-psr15-middlewares - middlewares/cors - Manage [Cross-Origin Resource Sharing (CORS)](http://www.w3.org/TR/cors/). (Packages / Security)
README
# middlewares/cors
[![Latest Version on Packagist][ico-version]][link-packagist]
[![Software License][ico-license]](LICENSE)
![Testing][ico-ga]
[![Total Downloads][ico-downloads]][link-downloads]Middleware to implement Cross-Origin Resource Sharing (CORS) using [neomerx/cors-psr7](https://github.com/neomerx/cors-psr7).
## Requirements
* PHP >= 7.2
* A [PSR-7 http library](https://github.com/middlewares/awesome-psr15-middlewares#psr-7-implementations)
* A [PSR-15 middleware dispatcher](https://github.com/middlewares/awesome-psr15-middlewares#dispatcher)## Installation
This package is installable and autoloadable via Composer as [middlewares/cors](https://packagist.org/packages/middlewares/cors).
```sh
composer require middlewares/cors
```## Example
```php
use Neomerx\Cors\Strategies\Settings;
use Neomerx\Cors\Analyzer;$settings = new Settings();
$settings->setServerOrigin('http', 'example.com', 123);$analyzer = Analyzer::instance($settings);
$dispatcher = new Dispatcher([
new Middlewares\Cors($analyzer)
]);$response = $dispatcher->dispatch(new ServerRequest());
```## Usage
You have to provide a `Neomerx\Cors\Contracts\AnalyzerInterface` to the constructor. See [neomerx/cors-psr7](https://github.com/neomerx/cors-psr7) for more info. Optionally, you can provide a `Psr\Http\Message\ResponseFactoryInterface` as the second argument to create the responses. If it's not defined, [Middleware\Utils\Factory](https://github.com/middlewares/utils#factory) will be used to detect it automatically.
```php
$analyzer = Analyzer::instance($settings);
$responseFactory = new MyOwnResponseFactory();$cors = new Middlewares\Cors($analyzer, $responseFactory);
```---
Please see [CHANGELOG](CHANGELOG.md) for more information about recent changes and [CONTRIBUTING](CONTRIBUTING.md) for contributing details.
The MIT License (MIT). Please see [LICENSE](LICENSE) for more information.
[ico-version]: https://img.shields.io/packagist/v/middlewares/cors.svg?style=flat-square
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[ico-ga]: https://github.com/middlewares/cors/workflows/testing/badge.svg
[ico-downloads]: https://img.shields.io/packagist/dt/middlewares/cors.svg?style=flat-square[link-packagist]: https://packagist.org/packages/middlewares/cors
[link-downloads]: https://packagist.org/packages/middlewares/cors