|
|
|
1
|
+<?php
|
|
|
|
2
|
+
|
|
|
|
3
|
+namespace App\Http\Middleware;
|
|
|
|
4
|
+
|
|
|
|
5
|
+use Closure;
|
|
|
|
6
|
+
|
|
|
|
7
|
+class EnableCrossRequestMiddleware
|
|
|
|
8
|
+{
|
|
|
|
9
|
+ /**
|
|
|
|
10
|
+ * Handle an incoming request.
|
|
|
|
11
|
+ *
|
|
|
|
12
|
+ * @param \Illuminate\Http\Request $request
|
|
|
|
13
|
+ * @param \Closure $next
|
|
|
|
14
|
+ * @return mixed
|
|
|
|
15
|
+ */
|
|
|
|
16
|
+ public function handle($request, Closure $next)
|
|
|
|
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
|
+ }
|
|
|
|
31
|
+} |