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-25 10:38:55 +01:00
|
|
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
2019-11-12 22:32:28 +01:00
|
|
|
|
|
|
|
class Cors
|
|
|
|
{
|
2019-12-30 22:59:12 +01:00
|
|
|
public function handle($request, Closure $next)
|
|
|
|
{
|
|
|
|
if ($request->getMethod() == "OPTIONS") {
|
|
|
|
header("Access-Control-Allow-Origin: *");
|
2019-11-12 22:50:12 +01:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
// ALLOW OPTIONS METHOD
|
|
|
|
$headers = [
|
|
|
|
'Access-Control-Allow-Methods'=> 'POST, GET, OPTIONS, PUT, DELETE',
|
2020-02-25 09:33:53 +01:00
|
|
|
'Access-Control-Allow-Headers'=> 'X-API-SECRET,X-API-TOKEN,X-API-PASSWORD,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'
|
2019-12-30 22:59:12 +01:00
|
|
|
];
|
2019-11-13 12:36:39 +01:00
|
|
|
|
|
|
|
return Response::make('OK', 200, $headers);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
/* Work around for file downloads where the response cannot contain have headers set */
|
|
|
|
// if($request instanceOf BinaryFileResponse)
|
|
|
|
// return $next($request);
|
|
|
|
// else
|
|
|
|
// return $next($request)
|
|
|
|
// ->header('Access-Control-Allow-Origin', '*')
|
|
|
|
// ->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
|
|
|
|
// ->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-13 12:36:39 +01:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
$response = $next($request);
|
2019-11-12 22:32:28 +01:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
$response->headers->set('Access-Control-Allow-Origin', '*');
|
|
|
|
$response->headers->set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
2020-02-17 10:37:44 +01:00
|
|
|
$response->headers->set('Access-Control-Allow-Headers', 'X-API-SECRET,X-API-TOKEN,X-API-PASSWORD,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range');
|
2020-03-02 11:22:37 +01:00
|
|
|
$response->headers->set('X-APP-VERSION', config('ninja.app_version'));
|
|
|
|
$response->headers->set('X-API-VERSION', config('ninja.api_version'));
|
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
}
|