* initial commit
This commit is contained in:
22
src/App/Middleware/PreFlightMiddleware.php
Normal file
22
src/App/Middleware/PreFlightMiddleware.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user