23 lines
863 B
PHP
23 lines
863 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Middleware;
|
||
|
|
|
||
|
|
use Psr\Http\Message\RequestInterface;
|
||
|
|
use Psr\Http\Message\ResponseInterface;
|
||
|
|
|
||
|
|
class PreFlightMiddleware
|
||
|
|
{
|
||
|
|
public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next)
|
||
|
|
{
|
||
|
|
$requestMethod = strtoupper($request->getMethod());
|
||
|
|
if ($requestMethod == 'OPTIONS') {
|
||
|
|
return $response
|
||
|
|
->withHeader('Accept', 'OPTIONS,GET,POST,PUT,PATCH,DELETE')
|
||
|
|
->withHeader('Access-Control-Allow-Origin', '*')
|
||
|
|
->withHeader('Access-Control-Allow-Methods', 'OPTIONS,GET,POST,PUT,PATCH,DELETE')
|
||
|
|
->withHeader('Access-Control-Allow-Headers', 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization');
|
||
|
|
}
|
||
|
|
return $next($request, $response);
|
||
|
|
}
|
||
|
|
}
|