From c02bf766fd9b3fee0383cb978e7609775859e07f Mon Sep 17 00:00:00 2001 From: Eva Ho Date: Mon, 15 Dec 2025 17:19:19 -0500 Subject: [PATCH] fix: windows app blank ui issue --- app/ui/app.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/app/ui/app.go b/app/ui/app.go index d73df2c02..e359215ee 100644 --- a/app/ui/app.go +++ b/app/ui/app.go @@ -7,7 +7,9 @@ import ( "embed" "errors" "io/fs" + "mime" "net/http" + "path/filepath" "strings" "time" ) @@ -15,6 +17,13 @@ import ( //go:embed app/dist var appFS embed.FS +func init() { + mime.AddExtensionType(".js", "application/javascript; charset=utf-8") + mime.AddExtensionType(".css", "text/css; charset=utf-8") + mime.AddExtensionType(".woff2", "font/woff2") + mime.AddExtensionType(".svg", "image/svg+xml") +} + // appHandler returns an HTTP handler that serves the React SPA. // It tries to serve real files first, then falls back to index.html for React Router. func (s *Server) appHandler() http.Handler { @@ -24,11 +33,19 @@ func (s *Server) appHandler() http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { p := strings.TrimPrefix(r.URL.Path, "/") - if _, err := fsys.Open(p); err == nil { - // Serve the file directly + + if file, err := fsys.Open(p); err == nil { + file.Close() + + // Ensure proper Content-Type headers + if contentType := mime.TypeByExtension(filepath.Ext(p)); contentType != "" { + w.Header().Set("Content-Type", contentType) + } + fileServer.ServeHTTP(w, r) return } + // Fallback – serve index.html for unknown paths so React Router works data, err := fs.ReadFile(fsys, "index.html") if err != nil { @@ -39,6 +56,8 @@ func (s *Server) appHandler() http.Handler { } return } + + w.Header().Set("Content-Type", "text/html; charset=utf-8") http.ServeContent(w, r, "index.html", time.Time{}, bytes.NewReader(data)) }) }