Skip to content

abellion/laravel-cors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

#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 :

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 :

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 :

use Abellion\Cors\Middleware\OptionsMiddleware;

OptionsMiddleware::$OPTIONS['Access-Control-Allow-Methods'] = "POST, PUT, DELETE, GET, OPTIONS, PATCH, HEAD";

About

Add CORS to your Laravel/Lumen app in 2 steps

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages