diff --git a/internal/filesystem/asset_handler.go b/internal/filesystem/asset_handler.go index 911900a..35a2fc5 100644 --- a/internal/filesystem/asset_handler.go +++ b/internal/filesystem/asset_handler.go @@ -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)