2019-11-12 22:32:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use Closure;
|
2019-11-13 12:39:53 +01:00
|
|
|
use Illuminate\Support\Facades\Response;
|
|
|
|
|
2019-11-12 22:32:28 +01:00
|
|
|
|
|
|
|
class Cors
|
|
|
|
{
|
2019-11-12 22:50:12 +01:00
|
|
|
|
2019-11-12 22:32:28 +01:00
|
|
|
public function handle($request, Closure $next)
|
|
|
|
{
|
|
|
|
|
2019-11-13 12:36:39 +01:00
|
|
|
if($request->getMethod() == "OPTIONS") {
|
|
|
|
header("Access-Control-Allow-Origin: *");
|
|
|
|
|
|
|
|
// ALLOW OPTIONS METHOD
|
|
|
|
$headers = [
|
|
|
|
'Access-Control-Allow-Methods'=> 'POST, GET, OPTIONS, PUT, DELETE',
|
|
|
|
'Access-Control-Allow-Headers'=> 'X-API-SECRET,X-API-TOKEN,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'
|
|
|
|
];
|
|
|
|
|
|
|
|
return Response::make('OK', 200, $headers);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-11-12 22:32:28 +01:00
|
|
|
return $next($request)
|
|
|
|
->header('Access-Control-Allow-Origin', '*')
|
|
|
|
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
|
2019-11-13 12:36:39 +01:00
|
|
|
->header('Access-Control-Allow-Headers', 'X-API-SECRET,X-API-TOKEN,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range');
|
2019-11-12 22:32:28 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|