From 3724f2e47d390eaa946c7a6e60cc79045b11a81e Mon Sep 17 00:00:00 2001 From: Dustin Pianalto Date: Thu, 6 Mar 2025 15:37:43 -0900 Subject: [PATCH] add htmx --- web/server.go | 16 +++++++++++++--- web/static/js/htmx.min.js | 0 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 web/static/js/htmx.min.js diff --git a/web/server.go b/web/server.go index 4a3f364..c228291 100644 --- a/web/server.go +++ b/web/server.go @@ -8,6 +8,7 @@ import ( "io/fs" "log" "net/http" + "net/url" "strings" "sync" "time" @@ -79,9 +80,18 @@ func (s *Server) routes() { w.Header().Set("Content-Type", "text/css") } - // Strip /static/ prefix before serving - r.URL.Path = strings.TrimPrefix(r.URL.Path, "/static") - fileServer.ServeHTTP(w, r) + // The key fix: properly handle the path + // Remove the /static prefix for the filesystem lookup + pathWithoutPrefix := strings.TrimPrefix(r.URL.Path, "/static") + + // Create a new request with the modified path + r2 := new(http.Request) + *r2 = *r + r2.URL = new(url.URL) + *r2.URL = *r.URL + r2.URL.Path = pathWithoutPrefix + + fileServer.ServeHTTP(w, r2) }) // API routes diff --git a/web/static/js/htmx.min.js b/web/static/js/htmx.min.js new file mode 100644 index 0000000..e69de29