LaravelPackages.net
Acme Inc.
Toggle sidebar
binjuhor/lumen-cors

Cross-origin resource sharing (CORS). Add CORS middleware for Lumen micro-framework

88
2
v1.0
About binjuhor/lumen-cors

binjuhor/lumen-cors is a Laravel package for cross-origin resource sharing (cors). add cors middleware for lumen micro-framework. It currently has 2 GitHub stars and 88 downloads on Packagist (latest version v1.0). Install it with composer require binjuhor/lumen-cors. Discover more Laravel packages by binjuhor or browse all Laravel packages to compare alternatives.

Last updated

Lumen-CORS

Cross-origin resource sharing (CORS) Middleware for Lumen micro-framework.

Installation

After you install lumen as per lumen docs, install lumen-cors from lumen folder.

Install with Composer

Run composer require binjuhor/lumen-cors to install lumen-cors.

Usage

Global CORS

If you want CORS enabled for every HTTP request to your application, head over to your bootstrap/app.php file and register your new middleware with the following lines:

$app->middleware([
    Binjuhor\Lumen\Middleware\CorsMiddleware::class
 ]);

CORS for Routes

If you would like to enable CORS to specific routes, you should first assign the lumen-cors middleware a short-hand key in your bootstrap/app.php file.

$app->routeMiddleware([
    'cors' => 'Binjuhor\Lumen\Middleware\LumenCors',
]);

Then, you use the key in the route options array.

$app->get('/api/products', ['middleware' => 'cors', function() {
    //Get all products with this route
}]);

More info. - Lumen Registering Middleware

License

MIT

Star History Chart