@@ -8,6 +8,7 @@ import ( |
| 8 | "net/http" | 8 | "net/http" |
| 9 | | 9 | |
| 10 | "github.com/tenseleyFlow/shithub/internal/version" | 10 | "github.com/tenseleyFlow/shithub/internal/version" |
| | 11 | + "github.com/tenseleyFlow/shithub/internal/web/middleware" |
| 11 | "github.com/tenseleyFlow/shithub/internal/web/render" | 12 | "github.com/tenseleyFlow/shithub/internal/web/render" |
| 12 | ) | 13 | ) |
| 13 | | 14 | |
@@ -23,6 +24,11 @@ type helloData struct { |
| 23 | Commit string | 24 | Commit string |
| 24 | BuiltAt string | 25 | BuiltAt string |
| 25 | LogoSVG template.HTML | 26 | LogoSVG template.HTML |
| | 27 | + // Viewer + CSRFToken mirror the fields _nav.html branches on. Typed |
| | 28 | + // page-data structs must populate them explicitly — the renderer |
| | 29 | + // only auto-injects for map[string]any data. |
| | 30 | + Viewer middleware.CurrentUser |
| | 31 | + CSRFToken string |
| 26 | // OG* are referenced by the shared _layout.html (S09). The fields | 32 | // OG* are referenced by the shared _layout.html (S09). The fields |
| 27 | // must exist on every typed page-data struct that goes through the | 33 | // must exist on every typed page-data struct that goes through the |
| 28 | // layout — html/template evaluates `{{ if .X }}` even on nil-checks | 34 | // layout — html/template evaluates `{{ if .X }}` even on nil-checks |
@@ -34,14 +40,16 @@ type helloData struct { |
| 34 | | 40 | |
| 35 | func (h helloHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | 41 | func (h helloHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| 36 | data := helloData{ | 42 | data := helloData{ |
| 37 | - Title: "Welcome", | 43 | + Title: "Welcome", |
| 38 | - Version: version.Version, | 44 | + Version: version.Version, |
| 39 | - Commit: version.Commit, | 45 | + Commit: version.Commit, |
| 40 | - BuiltAt: version.BuiltAt, | 46 | + BuiltAt: version.BuiltAt, |
| 41 | - LogoSVG: template.HTML(h.logoSVG), // #nosec G203 — embedded server-owned asset | 47 | + LogoSVG: template.HTML(h.logoSVG), // #nosec G203 — embedded server-owned asset |
| | 48 | + Viewer: middleware.CurrentUserFromContext(r.Context()), |
| | 49 | + CSRFToken: middleware.CSRFTokenForRequest(r), |
| 42 | } | 50 | } |
| 43 | w.Header().Set("Content-Type", "text/html; charset=utf-8") | 51 | w.Header().Set("Content-Type", "text/html; charset=utf-8") |
| 44 | - if err := h.render.Render(w, "hello", data); err != nil { | 52 | + if err := h.render.RenderPage(w, r, "hello", data); err != nil { |
| 45 | h.logger.Error("render hello", "error", err) | 53 | h.logger.Error("render hello", "error", err) |
| 46 | http.Error(w, "internal server error", http.StatusInternalServerError) | 54 | http.Error(w, "internal server error", http.StatusInternalServerError) |
| 47 | } | 55 | } |