fix cors v2

This commit is contained in:
Doar Mihai
2026-03-24 22:25:41 +02:00
parent c7df826f74
commit 908ea1c868
+16 -4
View File
@@ -25,15 +25,27 @@ class CollectCors
private function corsHeaders(Request $request): array
{
// Get the origin from the request, default to '*' if not present
$origin = $request->header('Origin', '*');
// Get the origin from the request
$origin = $request->header('Origin');
// If origin is present, allow it with credentials
// Otherwise, use wildcard without credentials
if ($origin) {
return [
'Access-Control-Allow-Origin' => $origin,
'Access-Control-Allow-Methods' => 'GET, POST, OPTIONS',
'Access-Control-Allow-Headers' => 'Content-Type, X-Requested-With',
'Access-Control-Max-Age' => '86400',
'Access-Control-Allow-Credentials' => 'true',
'Vary' => 'Origin',
];
}
return [
'Access-Control-Allow-Origin' => $origin,
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Methods' => 'GET, POST, OPTIONS',
'Access-Control-Allow-Headers' => 'Content-Type, X-Requested-With',
'Access-Control-Max-Age' => '86400',
'Access-Control-Allow-Credentials' => 'true',
];
}
}