for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Yiisoft\Yii\Debug\Api\Middleware;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Yiisoft\Http\Header;
/**
* Adds CORS headers to response.
*/
final class Cors implements MiddlewareInterface
{
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
$response = $handler->handle($request);
return $response
->withHeader(Header::ALLOW, '*')
->withHeader(Header::VARY, 'Origin')
->withHeader(Header::ACCESS_CONTROL_ALLOW_ORIGIN, '*')
->withHeader(Header::ACCESS_CONTROL_ALLOW_METHODS, 'GET,OPTIONS,HEAD')
->withHeader(Header::ACCESS_CONTROL_ALLOW_HEADERS, '*')
->withHeader(Header::ACCESS_CONTROL_ALLOW_CREDENTIALS, 'true');
}