Enabled CORS locally

This commit is contained in:
Josef Citrine 2017-01-02 19:56:17 +00:00
parent b163d70e9c
commit f7bc4f0565
3 changed files with 20 additions and 1 deletions

View file

@ -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,
];
}

View file

@ -0,0 +1,18 @@
<?php
namespace Poniverse\Ponyfm\Http\Middleware;
use App;
class Cors {
public function handle($request, $next)
{
if (App::environment('local', 'staging')) {
return $next($request)
->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
} else {
return $next($request);
}
}
}

View file

@ -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');