From 0de89e6bc6a467b2cc4261ae65464f40119cc0ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Herg=C3=A8s?= Date: Fri, 3 Oct 2025 18:40:45 +0200 Subject: feat(frontend): use htmx to dynamically navigate between pages --- backend/router.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'backend/router.go') diff --git a/backend/router.go b/backend/router.go index 33c685d..22c77a4 100644 --- a/backend/router.go +++ b/backend/router.go @@ -15,7 +15,11 @@ import ( "github.com/go-chi/httplog/v3" ) -const Version = "0.1.0" +const ( + Version = "0.1.0" + configKey = "config" + isUpdateKey = "is_update" +) //go:embed templates var templates embed.FS @@ -62,7 +66,17 @@ func NewRouter(debug bool, cfg *Config) *chi.Mux { })) r.Use(func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - ctx := context.WithValue(r.Context(), "config", cfg) + ctx := context.WithValue(r.Context(), configKey, cfg) + next.ServeHTTP(w, r.WithContext(ctx)) + }) + }) + r.Use(func(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + val := false + if r.Header.Get("HX-Request") == "true" { + val = true + } + ctx := context.WithValue(r.Context(), isUpdateKey, val) next.ServeHTTP(w, r.WithContext(ctx)) }) }) -- cgit v1.2.3