diff --git a/internal/server/routes.go b/internal/server/routes.go index 2cd1530..2c15e75 100644 --- a/internal/server/routes.go +++ b/internal/server/routes.go @@ -73,10 +73,17 @@ func (s *Server) SetupRoutes() { fileServer := http.FileServer(http.FS(distFS)) s.router.Get("/*", func(w http.ResponseWriter, r *http.Request) { + readFS, ok := distFS.(fs.ReadFileFS) + if !ok { + http.Error(w, "internal error", http.StatusInternalServerError) + + return + } + // Try to serve the file; if not found, serve index.html for SPA routing - f, err := distFS.(fs.ReadFileFS).ReadFile(r.URL.Path[1:]) + f, err := readFS.ReadFile(r.URL.Path[1:]) if err != nil || len(f) == 0 { - indexHTML, _ := distFS.(fs.ReadFileFS).ReadFile("index.html") + indexHTML, _ := readFS.ReadFile("index.html") w.Header().Set("Content-Type", "text/html; charset=utf-8") w.WriteHeader(http.StatusOK)