Files
AIclinicalresearch/backend/fix-cors.ps1
AI Clinical Dev Team 239c7ea85e feat: Day 21-22 - knowledge base frontend completed, fix CORS and file upload issues
- Complete knowledge base list and detail pages
- Complete document upload component
- Fix CORS config (add PUT/DELETE method support)
- Fix file upload issues (disabled state and beforeUpload return value)
- Add detailed debug logs (cleaned up)
- Create Day 21-22 completion summary document
2025-10-11 15:40:12 +08:00

35 lines
1.3 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 修复CORS配置脚本
Write-Host "🔧 正在修复CORS配置..." -ForegroundColor Green
$filePath = "src\index.ts"
$content = Get-Content $filePath -Raw
# 在CORS配置后添加日志
$content = $content -replace "(await fastify\.register\(cors, \{[^}]+\}\);)", "`$1`nconsole.log('✅ CORS已配置: 允许所有HTTP方法 (GET, POST, PUT, DELETE, PATCH, OPTIONS)');"
# 在multipart配置后添加日志
$content = $content -replace "(await fastify\.register\(multipart, \{[^}]+\}\);)", "`$1`nconsole.log('✅ 文件上传插件已配置: 最大文件大小 10MB');"
# 修改CORS配置为完整版本
$oldCors = "await fastify.register(cors, \{\s+origin: true, // 开发环境允许所有来源\s+credentials: true,\s+\}\);"
$newCors = @"
await fastify.register(cors, {
origin: true,
credentials: true,
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'],
allowedHeaders: ['Content-Type', 'Authorization', 'X-Requested-With', 'Accept', 'Origin'],
exposedHeaders: ['Content-Range', 'X-Content-Range'],
maxAge: 600,
preflightContinue: false,
});
"@
$content = $content -replace $oldCors, $newCors
# 保存文件
Set-Content $filePath $content -Encoding UTF8
Write-Host "✅ CORS配置已修复请重启后端服务。" -ForegroundColor Green