正在显示
1 个修改的文件
包含
8 行增加
和
1 行删除
| @@ -16,9 +16,16 @@ class EnableCrossRequestMiddleware | @@ -16,9 +16,16 @@ class EnableCrossRequestMiddleware | ||
| 16 | public function handle($request, Closure $next) | 16 | public function handle($request, Closure $next) |
| 17 | { | 17 | { |
| 18 | $response = $next($request); | 18 | $response = $next($request); |
| 19 | - $response->header('Access-Control-Allow-Origin', '*'); | 19 | + $http_origin = "*"; |
| 20 | + if(isset($_SERVER['HTTP_ORIGIN'])){ | ||
| 21 | + $http_origin = $_SERVER['HTTP_ORIGIN']; | ||
| 22 | + } | ||
| 23 | + $response->header('Access-Control-Allow-Origin', $http_origin); | ||
| 20 | $response->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS'); | 24 | $response->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS'); |
| 21 | $response->header('Access-Control-Allow-Headers', 'Origin, Content-Type, Authorization'); | 25 | $response->header('Access-Control-Allow-Headers', 'Origin, Content-Type, Authorization'); |
| 26 | + if (strtolower($_SERVER['REQUEST_METHOD']) == 'options') { | ||
| 27 | + exit; | ||
| 28 | + } | ||
| 22 | return $response; | 29 | return $response; |
| 23 | // 指定允许其他域名访问 | 30 | // 指定允许其他域名访问 |
| 24 | // $http_origin = "*"; | 31 | // $http_origin = "*"; |
-
请 注册 或 登录 后发表评论