daily-ci-api/src/App/Middleware/PreFlightMiddleware.php

23 lines
863 B
PHP
Raw Normal View History

2017-02-17 15:48:05 +01:00
<?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);
}
}