From d0cece053dbaaaaf7f69be08b91449e704c05c88 Mon Sep 17 00:00:00 2001 From: hugh <1012760428@qq.com> Date: Sat, 7 Feb 2026 00:36:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20CORS=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E4=BB=A5=E6=94=AF=E6=8C=81=20PUT/DELETE=20=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 问题 前端调用 PUT/DELETE 接口时出现 CORS 预检失败,导致网络错误: - PUT /api/v1/llm-configs/{id} - 更新配置失败 - DELETE /api/v1/llm-configs/{id} - 删除配置失败 ## 修复 在 backend/src/app.ts 中明确添加允许的 HTTP 方法列表: - 添加 methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'] - 确保 CORS 预检请求(OPTIONS)正确处理 ## 测试 使用 Playwright 测试 LLM 配置功能,所有功能正常: ✅ 切换启用/禁用状态 ✅ 编辑配置 ✅ 新增配置 ✅ 删除配置 Co-Authored-By: Claude Sonnet 4.5 --- backend/src/app.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/src/app.ts b/backend/src/app.ts index b68069d..360a9f3 100644 --- a/backend/src/app.ts +++ b/backend/src/app.ts @@ -38,6 +38,7 @@ async function registerPlugins(): Promise { await app.register(cors, { origin: true, credentials: true, + methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], }); logger.info('CORS 插件已注册'); }