/** * Execute the middleware. * * @param Request $request * @param Response $response * @param callable $next * * @return Response */ public function __invoke(Request $request, Response $response, callable $next) { $response = $response->withHeader('Access-Control-Allow-Origin', '*')->withHeader('Access-Control-Allow-Headers', ['Content-Type'])->withHeader('Access-Control-Allow-Methods', ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS']); if ($request->isOptions()) { return $response; } // Call next middleware return $next($request, $response); }