修复 CORS 配置以支持 PUT/DELETE 请求
## 问题
前端调用 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 <noreply@anthropic.com>
This commit is contained in:
1 parent
311f09fb0c
commit
d0cece053d
1 file changed
+1
@@ -38,6 +38,7 @@ async function registerPlugins(): Promise<void> {
|
|||||||
await app.register(cors, {
|
await app.register(cors, {
|
||||||
origin: true,
|
origin: true,
|
||||||
credentials: true,
|
credentials: true,
|
||||||
|
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
||||||
});
|
});
|
||||||
logger.info('CORS 插件已注册');
|
logger.info('CORS 插件已注册');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user