From f7bc4f0565ef4e3183b9fa5feec99d59dd9eb04c Mon Sep 17 00:00:00 2001 From: Josef Citrine Date: Mon, 2 Jan 2017 19:56:17 +0000 Subject: [PATCH] Enabled CORS locally --- app/Http/Kernel.php | 1 + app/Http/Middleware/Cors.php | 18 ++++++++++++++++++ routes/web.php | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 app/Http/Middleware/Cors.php diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 39449569..4fbe8dad 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -58,5 +58,6 @@ class Kernel extends HttpKernel 'json-exceptions' => \Poniverse\Ponyfm\Http\Middleware\JsonExceptions::class, 'guest' => \Poniverse\Ponyfm\Http\Middleware\RedirectIfAuthenticated::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, + 'cors' => \Poniverse\Ponyfm\Http\Middleware\Cors::class, ]; } diff --git a/app/Http/Middleware/Cors.php b/app/Http/Middleware/Cors.php new file mode 100644 index 00000000..56146242 --- /dev/null +++ b/app/Http/Middleware/Cors.php @@ -0,0 +1,18 @@ +header('Access-Control-Allow-Origin', '*') + ->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS'); + } else { + return $next($request); + } + } +} diff --git a/routes/web.php b/routes/web.php index 751fc104..b54073ab 100644 --- a/routes/web.php +++ b/routes/web.php @@ -99,7 +99,7 @@ Route::group(['prefix' => 'api/v1', 'middleware' => 'json-exceptions'], function }); -Route::group(['prefix' => 'api/web'], function () { +Route::group(['prefix' => 'api/web', 'middleware' => 'cors'], function () { Route::post('/alexa', 'Api\Web\AlexaController@handle'); Route::get('/taxonomies/all', 'Api\Web\TaxonomiesController@getAll');