getMethod() === 'OPTIONS') { return $this->withCorsHeaders(new Response(204)); } return $this->withCorsHeaders($handler->handle($request)); } private function withCorsHeaders(ResponseInterface $response): ResponseInterface { return $response ->withHeader('Access-Control-Allow-Origin', self::ALLOWED_ORIGIN) ->withHeader('Access-Control-Allow-Credentials', 'true') ->withHeader( 'Access-Control-Allow-Headers', 'Content-Type, Authorization', ) ->withHeader( 'Access-Control-Allow-Methods', 'GET, POST, OPTIONS', ); } }