From 7bfe7cba5c95f004c1b88f40ab18697efb75e213 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Mon, 25 May 2026 21:40:09 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20coolify=20proxy=20no=20retorna=20502=20p?= =?UTF-8?q?ara=20evitar=20intercepci=C3=B3n=20de=20Cloudflare?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cambia StatusBadGateway (502) → StatusBadRequest (400) en todos los errores del proxy Coolify. Cloudflare intercepta respuestas 502 del origen y muestra su propia pantalla, ocultando el error al frontend. Con 400, el JSON de error llega al cliente y Alpine.js puede mostrarlo. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- rest/controllers/coolify_controller.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/rest/controllers/coolify_controller.go b/rest/controllers/coolify_controller.go index 1cf4dfe..18cd072 100644 --- a/rest/controllers/coolify_controller.go +++ b/rest/controllers/coolify_controller.go @@ -54,12 +54,17 @@ func coolifyProxy(c *fiber.Ctx, method, endpoint string) error { } body, status, err := coolifyDo(method, ep, bodyReader, ct, cfg) if err != nil { - return c.Status(fiber.StatusBadGateway).JSON(fiber.Map{"error": err.Error()}) + // No devolver 502: Cloudflare lo intercepta y oculta el error al frontend + return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "No se pudo conectar a Coolify: " + err.Error()}) } var result json.RawMessage if err := json.Unmarshal(body, &result); err != nil { result = json.RawMessage(fmt.Sprintf(`{"raw":%q}`, string(body))) } + // Si Coolify devuelve 5xx, bajar a 400 para que Cloudflare no lo intercepte + if status >= 500 { + status = fiber.StatusBadRequest + } c.Status(status) return c.JSON(result) } @@ -122,7 +127,7 @@ func CoolifyTestConnection(c *fiber.Ctx) error { client := &http.Client{Timeout: 10 * time.Second} resp, err := client.Get(base + "/api/health") if err != nil { - return c.Status(fiber.StatusBadGateway).JSON(fiber.Map{"error": err.Error()}) + return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "No se pudo conectar a Coolify: " + err.Error()}) } defer resp.Body.Close() body, _ := io.ReadAll(io.LimitReader(resp.Body, 64*1024))