fix: buffer template execution to prevent corrupt HTML responses (closes #42)

Add renderTemplate helper method on Handlers that renders templates to a
bytes.Buffer first, then writes to the ResponseWriter only on success.
This prevents partial/corrupt HTML when template execution fails partway
through.

Applied to all template rendering call sites in:
- setup.go (HandleSetupGET, renderSetupError)
- auth.go (HandleLoginGET, HandleLoginPOST error paths)
- dashboard.go (HandleDashboard)
- app.go (HandleAppNew, HandleAppCreate, HandleAppDetail, HandleAppEdit,
  HandleAppUpdate, HandleAppDeployments)
This commit is contained in:
user
2026-02-15 22:04:09 -08:00
parent e9bf63d18b
commit af9ffddf84
6 changed files with 111 additions and 42 deletions

View File

@@ -69,10 +69,6 @@ func (h *Handlers) HandleDashboard() http.HandlerFunc {
"AppStats": appStats,
}, request)
execErr := tmpl.ExecuteTemplate(writer, "dashboard.html", data)
if execErr != nil {
h.log.Error("template execution failed", "error", execErr)
http.Error(writer, "Internal Server Error", http.StatusInternalServerError)
}
h.renderTemplate(writer, tmpl, "dashboard.html", data)
}
}