diff --git a/app/Http/Middleware/CorsMiddleware.php b/app/Http/Middleware/CorsMiddleware.php new file mode 100644 index 0000000..2431413 --- /dev/null +++ b/app/Http/Middleware/CorsMiddleware.php @@ -0,0 +1,41 @@ + '*', + 'Access-Control-Allow-Methods' => 'POST, GET, OPTIONS, PUT, DELETE', + 'Access-Control-Allow-Credentials' => 'true', + 'Access-Control-Max-Age' => '86400', + 'Access-Control-Allow-Headers' => 'Content-Type, Authorization, X-Requested-With' + ]; + + if ($request->isMethod('OPTIONS')) + { + return response()->json('{"method":"OPTIONS"}', 200, $headers); + } + + $response = $next($request); + foreach($headers as $key => $value) + { + $response->header($key, $value); + } + + return $response; + } +} diff --git a/bootstrap/app.php b/bootstrap/app.php index 76056f9..24a6b86 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -79,6 +79,10 @@ $app->configure('app'); // 'auth' => App\Http\Middleware\Authenticate::class, // ]); +$app->middleware([ + \App\Http\Middleware\CorsMiddleware::class +]); + $app->routeMiddleware([ 'auth' => App\Http\Middleware\FirebaseMiddleware::class, ]);