diff --git a/app/Http/Middleware/CorsMiddleware.php b/app/Http/Middleware/CorsMiddleware.php new file mode 100644 index 0000000..8dc0d2a --- /dev/null +++ b/app/Http/Middleware/CorsMiddleware.php @@ -0,0 +1,38 @@ + '*', + '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; + } +} \ No newline at end of file diff --git a/bootstrap/app.php b/bootstrap/app.php index 4808f2c..454bd0a 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -112,4 +112,8 @@ $app->router->group([ require __DIR__.'/../routes/web.php'; }); +$app->middleware([ + App\Http\Middleware\CorsMiddleware::class + ]); + return $app;