作者 zhl

u

@@ -15,19 +15,24 @@ class EnableCrossRequestMiddleware @@ -15,19 +15,24 @@ class EnableCrossRequestMiddleware
15 */ 15 */
16 public function handle($request, Closure $next) 16 public function handle($request, Closure $next)
17 { 17 {
  18 + $response = $next($request);
  19 + $response->header('Access-Control-Allow-Origin', '*');
  20 + $response->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
  21 + $response->header('Access-Control-Allow-Headers', 'Origin, Content-Type, Authorization');
  22 + return $response;
18 // 指定允许其他域名访问 23 // 指定允许其他域名访问
19 - $http_origin = "*";  
20 - if(isset($_SERVER['HTTP_ORIGIN'])){  
21 - $http_origin = $_SERVER['HTTP_ORIGIN'];  
22 - }  
23 - header("Access-Control-Allow-Origin:".$http_origin);  
24 - header('Access-Control-Allow-Methods:POST,GET'); //支持的http 动作  
25 - header('Access-Control-Allow-Credentials: true');  
26 - header('Access-Control-Max-Age: 1000');  
27 - header('Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept, Authorization, token'); //响应头 请按照自己需求添加。  
28 - if (strtolower($_SERVER['REQUEST_METHOD']) == 'options') {  
29 - exit;  
30 - }  
31 - return $next($request); 24 +// $http_origin = "*";
  25 +// if(isset($_SERVER['HTTP_ORIGIN'])){
  26 +// $http_origin = $_SERVER['HTTP_ORIGIN'];
  27 +// }
  28 +// header("Access-Control-Allow-Origin:".$http_origin);
  29 +// header('Access-Control-Allow-Methods:POST,GET'); //支持的http 动作
  30 +// header('Access-Control-Allow-Credentials: true');
  31 +// header('Access-Control-Max-Age: 1000');
  32 +// header('Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept, Authorization, token'); //响应头 请按照自己需求添加。
  33 +// if (strtolower($_SERVER['REQUEST_METHOD']) == 'options') {
  34 +// exit;
  35 +// }
  36 +// return $next($request);
32 } 37 }
33 } 38 }