From a2412b7cd2f5eb3c46052fbe15a3431a945b7e67 Mon Sep 17 00:00:00 2001 From: swanadiva Date: Tue, 7 Jul 2026 15:56:54 +0700 Subject: [PATCH] =?UTF-8?q?fix:=20host=20modal=20=E2=80=94=20single=20POST?= =?UTF-8?q?=20endpoint=20for=20create+edit,=20remove=20hx-put=20conflict?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - hx-put="" (empty) was causing HTMX to send wrong requests - Now use single hx-post="/hosts" with hidden hostId field - Server checks hostId: empty → create, present → update - UpdateHost reads ID from both URL param and form data --- app/backend/internal/handler/dashboard.go | 12 ++++++++++-- app/backend/views/host_modal.html | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/backend/internal/handler/dashboard.go b/app/backend/internal/handler/dashboard.go index 40b8bd1..0e861bc 100644 --- a/app/backend/internal/handler/dashboard.go +++ b/app/backend/internal/handler/dashboard.go @@ -51,6 +51,12 @@ func parsePort(s string, def int) int { } func CreateHost(c *fiber.Ctx) error { + hostID := c.FormValue("hostId") + + if hostID != "" { + return UpdateHost(c) + } + name := c.FormValue("name") ip := c.FormValue("ip") if name == "" || ip == "" { @@ -77,9 +83,8 @@ func CreateHost(c *fiber.Ctx) error { h.AuthType = "key" } - created := hostStore.AddFull(h) + hostStore.AddFull(h) hosts := hostStore.All() - _ = created return c.Render("host_list", fiber.Map{ "Hosts": hosts, "Active": countByStatus(hosts, "active"), @@ -89,6 +94,9 @@ func CreateHost(c *fiber.Ctx) error { func UpdateHost(c *fiber.Ctx) error { id := c.Params("id") + if id == "" { + id = c.FormValue("hostId") + } existing, found := hostStore.Get(id) if !found { return c.Status(404).SendString("host not found") diff --git a/app/backend/views/host_modal.html b/app/backend/views/host_modal.html index 415823d..e0ad7eb 100644 --- a/app/backend/views/host_modal.html +++ b/app/backend/views/host_modal.html @@ -15,11 +15,11 @@ -
+