| 1234567891011121314151617181920 |
- <?php
- declare(strict_types=1);
- namespace app\api\middleware;
- class AllowCrossDomain{
-
- public function handle($request, \Closure $next)
- {
- header('Access-Control-Allow-Origin: *'); // 或者指定具体域名
- header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
- header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
- header('Access-Control-Allow-Credentials: true');
-
- if ($request->method() === 'OPTIONS') {
- return response()->code(204);
- }
-
- return $next($request);
- }
- }
|