'true', 'Access-Control-Max-Age' => '1800', 'Access-Control-Allow-Methods' => '*', 'Access-Control-Allow-Headers' => '*', ]; public function process(Request $request, callable $handler): Response { $path = trim($request->path(), '/'); if (!str_starts_with($path, 'api/') && !str_starts_with($path, 'admin/')) { return $handler($request); } $header = $this->header; $origin = $request->header('origin'); if ($origin) { $info = parse_url($origin); $corsDomain = explode(',', config('buildadmin.cors_request_domain', '')); $corsDomain[] = $request->host(true); if ( in_array('*', $corsDomain) || in_array($origin, $corsDomain) || (isset($info['host']) && in_array($info['host'], $corsDomain)) ) { $header['Access-Control-Allow-Origin'] = $origin; } } if ($request->method() === 'OPTIONS') { return response('', 204, $header); } $response = $handler($request); return $response->withHeaders($header); } }