修复若干bug

This commit is contained in:
2026-03-10 22:24:06 +08:00
parent 7cdb591f69
commit 98156991c1
16 changed files with 1021 additions and 892 deletions
+4 -30
View File
@@ -15,47 +15,21 @@ class AllowCrossDomain
{
$origin = $request->header('origin', '');
$allowedDomains = [
'http://localhost:3000',
'http://localhost:5000',
'http://localhost:8000',
'http://127.0.0.1:3000',
'http://127.0.0.1:5000',
'http://127.0.0.1:8000',
'http://localhost:5173',
'http://backapi.yunzer.cn',
'http://www.yunzer.cn',
'https://www.yunzer.cn',
'http://yunzer.cn',
'https://yunzer.cn',
'http://back.yunzer.cn',
'https://back.yunzer.cn',
'http://backend.yunzer.cn',
'https://backend.yunzer.cn',
];
if (in_array($origin, $allowedDomains)) {
$header['Access-Control-Allow-Origin'] = $origin;
} else {
if (!empty($origin)) {
$header['Access-Control-Allow-Origin'] = $origin;
} else {
$header['Access-Control-Allow-Origin'] = '*';
}
}
// 允许所有来源(生产环境建议限制具体域名)
$header['Access-Control-Allow-Origin'] = $origin ?: '*';
if ($request->method() === 'OPTIONS') {
$header['Access-Control-Allow-Credentials'] = 'true';
$header['Access-Control-Max-Age'] = 1800;
$header['Access-Control-Allow-Methods'] = 'GET, POST, PATCH, PUT, DELETE, OPTIONS';
$header['Access-Control-Allow-Headers'] = 'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With';
$header['Access-Control-Allow-Headers'] = 'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With, X-Current-Domain';
return response('', 200, $header);
}
$header['Access-Control-Allow-Credentials'] = 'true';
$header['Access-Control-Max-Age'] = 1800;
$header['Access-Control-Allow-Methods'] = 'GET, POST, PATCH, PUT, DELETE, OPTIONS';
$header['Access-Control-Allow-Headers'] = 'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With';
$header['Access-Control-Allow-Headers'] = 'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With, X-Current-Domain';
return $next($request)->header($header);
}