Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abellion/laravel-cors
Add CORS to your Laravel/Lumen app in 2 steps
https://github.com/abellion/laravel-cors
laravel laravel-cors lumen
Last synced: 9 days ago
JSON representation
Add CORS to your Laravel/Lumen app in 2 steps
- Host: GitHub
- URL: https://github.com/abellion/laravel-cors
- Owner: abellion
- Created: 2016-10-09T22:22:51.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-02-09T17:04:38.000Z (almost 8 years ago)
- Last Synced: 2024-11-02T03:05:39.556Z (14 days ago)
- Topics: laravel, laravel-cors, lumen
- Language: PHP
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
#Laravel CORS
## Add CORS to your Laravel/Lumen app in 2 steps :
#### Require the package :
```
composer require abellion/laravel-cors
```#### Add the service provider to your app :
```php
Abellion\Cors\LaravelServiceProvider::class
```- **Laravel** : In the `providers` array of the ```config/app.php``` file
- **Lumen** : In the ```bootstrap/app.php``` file using the ```$app->register();``` method.**You're all set ! All origins are allowed by default. If you want to config your own domains, see bellow.**
## Configuring allowed origins :
By default all origins are allowed. You can add your own config by modifying the ```ORIGINS``` array from the ```OriginsMiddleware``` class :
```php
use Abellion\Cors\Middleware\OriginsMiddleware;OriginsMiddleware::$ORIGINS = [
"/https:\/\/(www\.)?([a-z0-9]+\.)?mydomain\.(com|fr)/",
"/http(s)?:\/\/(www\.)?localhost(:[0-9]+)?/"
];
```All origins that match one of the regex will be added. In this example ```localhost``` and ```mydomain``` are allowed.
## Configuring other headers :
```php
use Abellion\Cors\Middleware\OptionsMiddleware;OptionsMiddleware::$OPTIONS['Access-Control-Allow-Methods'] = "POST, PUT, DELETE, GET, OPTIONS, PATCH, HEAD";
```