e
Showing
2 changed files
with
25 additions
and
8 deletions
| ... | @@ -137,7 +137,8 @@ class ApiController extends Controller | ... | @@ -137,7 +137,8 @@ class ApiController extends Controller |
| 137 | $response = $pdf; | 137 | $response = $pdf; |
| 138 | $statusCode = 200; | 138 | $statusCode = 200; |
| 139 | 139 | ||
| 140 | return Response::json($response, $statusCode)->header('Access-Control-Allow-Origin', '*'); | 140 | |
| 141 | return Response::json($response, $statusCode) | ||
| 141 | 142 | ||
| 142 | 143 | ||
| 143 | 144 | ... | ... |
| 1 | <?php | 1 | <?php |
| 2 | |||
| 3 | namespace App\Http\Middleware; | 2 | namespace App\Http\Middleware; |
| 4 | 3 | ||
| 5 | use Closure; | 4 | use Closure; |
| 6 | use Illuminate\Contracts\Routing\Middleware; | ||
| 7 | use Illuminate\Session\TokenMismatchException; | ||
| 8 | 5 | ||
| 9 | class Cors implements Middleware { | ||
| 10 | 6 | ||
| 7 | class Cors | ||
| 8 | { | ||
| 9 | /** | ||
| 10 | * Handle an incoming request. | ||
| 11 | * | ||
| 12 | * @param \Illuminate\Http\Request $request | ||
| 13 | * @param \Closure $next | ||
| 14 | * @return mixed | ||
| 15 | */ | ||
| 11 | public function handle($request, Closure $next) | 16 | public function handle($request, Closure $next) |
| 12 | { | 17 | { |
| 13 | $response = $next($request); | 18 | header("Access-Control-Allow-Origin: *"); |
| 14 | $response->headers->set('Access-Control-Allow-Origin', '*')->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS'); | ||
| 15 | 19 | ||
| 16 | return $response; | 20 | // ALLOW OPTIONS METHOD |
| 21 | $headers = [ | ||
| 22 | 'Access-Control-Allow-Methods'=> 'POST, GET, OPTIONS, PUT, DELETE', | ||
| 23 | 'Access-Control-Allow-Headers'=> 'Content-Type, X-Auth-Token, Origin' | ||
| 24 | ]; | ||
| 25 | if($request->getMethod() == "OPTIONS") { | ||
| 26 | // The client-side application can set only headers allowed in Access-Control-Allow-Headers | ||
| 27 | return Response::make('OK', 200, $headers); | ||
| 17 | } | 28 | } |
| 18 | 29 | ||
| 30 | $response = $next($request); | ||
| 31 | foreach($headers as $key => $value) | ||
| 32 | $response->header($key, $value); | ||
| 33 | return $response; | ||
| 34 | } | ||
| 19 | } | 35 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or sign in to post a comment