From 18dfebf0de49b1acd586122e8a60d1918541364a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=AB=E5=9C=B0=E5=83=A7?= <357099073@qq.com> Date: Wed, 28 Jan 2026 23:37:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=85=AC=E5=85=B1=E8=B7=A8?= =?UTF-8?q?=E5=9F=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 4 ++-- app/admin/middleware.php | 1 + .../middleware/AllowCrossDomain.php} | 15 +++++---------- app/index/middleware.php | 9 +-------- 4 files changed, 9 insertions(+), 20 deletions(-) rename app/{admin/middleware/CustomCors.php => common/middleware/AllowCrossDomain.php} (83%) diff --git a/.env b/.env index 4427831..63b031b 100644 --- a/.env +++ b/.env @@ -1,8 +1,8 @@ APP_DEBUG = true DB_TYPE = mysql -DB_HOST = 10.168.1.239 -DB_NAME = official_website +DB_HOST = 192.168.31.10 +DB_NAME = official_webiste DB_USER = official DB_PASS = meitian@#! DB_PORT = 3306 diff --git a/app/admin/middleware.php b/app/admin/middleware.php index dcc6340..cb3dd53 100644 --- a/app/admin/middleware.php +++ b/app/admin/middleware.php @@ -6,6 +6,7 @@ return [ // 多语言加载 // \think\middleware\LoadLangPack::class, // Session初始化 + \app\common\middleware\AllowCrossDomain::class, \think\middleware\SessionInit::class, ]; diff --git a/app/admin/middleware/CustomCors.php b/app/common/middleware/AllowCrossDomain.php similarity index 83% rename from app/admin/middleware/CustomCors.php rename to app/common/middleware/AllowCrossDomain.php index ac49a85..4a48222 100644 --- a/app/admin/middleware/CustomCors.php +++ b/app/common/middleware/AllowCrossDomain.php @@ -1,28 +1,27 @@ header('origin', ''); - // 允许的域名列表(根据实际情况修改) $allowedDomains = [ 'http://localhost:3000', 'http://localhost:8000', 'http://127.0.0.1:3000', 'http://127.0.0.1:8000', - 'http://backapi.yunzer.cn', 'http://localhost:5173', + 'http://backapi.yunzer.cn', 'http://www.yunzer.cn', 'https://www.yunzer.cn', 'http://yunzer.cn', @@ -33,11 +32,9 @@ class CustomCors '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 { @@ -45,13 +42,11 @@ class CustomCors } } - // 处理 OPTIONS 预检请求,直接返回 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'; - \think\facade\Log::record('CORS OPTIONS preflight for: ' . $origin); return response('', 200, $header); } diff --git a/app/index/middleware.php b/app/index/middleware.php index e429d41..bbc4c05 100644 --- a/app/index/middleware.php +++ b/app/index/middleware.php @@ -1,12 +1,5 @@