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