12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace App\Http\Middleware;
- use Closure;
- class EnableCrossRequestMiddleware
- {
- /**
- * Handle an incoming request.
- *
- * @param \Illuminate\Http\Request $request
- * @param \Closure $next
- * @return mixed
- */
- public function handle($request, Closure $next)
- {
- $response = $next($request);
- $response->header('Access-Control-Allow-Origin', '*');
- $response->header('Access-Control-Allow-Headers', 'Origin, Content-Type, Cookie, X-CSRF-TOKEN, Accept, Authorization, X-XSRF-TOKEN');
- $response->header('Access-Control-Expose-Headers', 'Authorization, authenticated');
- $response->header('Access-Control-Allow-Methods', 'GET, POST, PATCH, PUT, OPTIONS');
- $response->header('Access-Control-Allow-Credentials', 'true');
-
- return $response;
- //
- // $response = $next($request);
- // if ($response instanceof Response) {
- // return $next($request)->header('Access-Control-Allow-Origin', '*')
- // ->header('Access-Control-Allow-Methods', 'GET,POST,PUT,OPTIONS,PATCH,DELETE,HEAD')
- // ->header('Access-Control-Allow-Headers', 'x-csrf-token,x-requested-with,content-type');
- // ->header('Access-Control-Expose-Headers', 'Authorization, authenticated');
- // ->header('Access-Control-Allow-Credentials', 'true');
- // }
- // // 如果是实列 \Symfony\Component\HttpFoundation\Response::class
- // $response->headers->set('Access-Control-Allow-Origin', '*');
- // $response->headers->set('Access-Control-Allow-Methods', 'GET,POST,PUT,OPTIONS,PATCH,DELETE,HEAD');
- // $response->headers->set('Access-Control-Allow-Headers', 'x-csrf-token,x-requested-with,content-type');
- // $response->headers->set('Access-Control-Expose-Headers', 'Authorization, authenticated');
- // $response->headers->set('Access-Control-Allow-Credentials', 'true');
- // return $response;
- }
- }
|