98efbb3f by Jeff Balicki

f

1 parent a36994a8
1 <?php 1 <?php
2 use Closure; 2 namespace App\Http\Middleware;
3 3
4 class CORS { 4 use Closure;
5 5
6 /** 6 class Cors {
7 * Handle an incoming request.
8 *
9 * @param \Illuminate\Http\Request $request
10 * @param \Closure $next
11 * @return mixed
12 */
13 public function handle($request, Closure $next) 7 public function handle($request, Closure $next)
14 { 8 {
15 9 return $next($request)
16 header("Access-Control-Allow-Origin: *"); 10 ->header('Access-Control-Allow-Origin', '*')
17 11 ->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
18 // ALLOW OPTIONS METHOD
19 $headers = [
20 'Access-Control-Allow-Methods'=> 'POST, GET, OPTIONS, PUT, DELETE',
21 'Access-Control-Allow-Headers'=> 'Content-Type, X-Auth-Token, Origin'
22 ];
23 if($request->getMethod() == "OPTIONS") {
24 // The client-side application can set only headers allowed in Access-Control-Allow-Headers
25 return Response::make('OK', 200, $headers);
26 } 12 }
27
28 $response = $next($request);
29 foreach($headers as $key => $value)
30 $response->header($key, $value);
31 return $response;
32 }
33
34 } 13 }
...\ No newline at end of file ...\ No newline at end of file
......