Private
Public Access
1
0

修复:本地文件服务器 CORS 支持

问题:
- 前端运行在 http://wails.localhost
- 文件服务器运行在 http://localhost:18765
- 不同源导致 CORS 错误

修复:
- asset_handler.go 添加 CORS 响应头
- 支持 OPTIONS 预检请求
- 允许所有源访问(本地文件服务器)
This commit is contained in:
2026-02-16 14:22:33 +08:00
parent e198fd4ee1
commit a6f99e0c49

View File

@@ -67,6 +67,17 @@ func StartLocalFileServer() (string, error) {
// handleLocalFileRequest 处理本地文件请求
func handleLocalFileRequest(w http.ResponseWriter, r *http.Request) {
// CORS 头:允许所有源访问(因为这是本地文件服务器)
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "*")
// 处理 OPTIONS 预检请求
if r.Method == http.MethodOptions {
w.WriteHeader(http.StatusOK)
return
}
// 只处理 GET 请求
if r.Method != http.MethodGet {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)