From 249c3d2a8f472088a42c4b59e09b53a207bd2e9d Mon Sep 17 00:00:00 2001 From: ga Date: Thu, 20 Aug 2026 21:38:27 +0000 Subject: [PATCH] =?UTF-8?q?Sprint=208.1:=20/api/v1/debug/log=20endpoint=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D1=81?= =?UTF-8?q?=D0=BA=D0=B8=D1=85=20=D0=BB=D0=BE=D0=B3=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/server/main.go | 1 + internal/handlers/handlers.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/cmd/server/main.go b/cmd/server/main.go index 71df5df..899042a 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -225,6 +225,7 @@ func main() { protected.Post("/auth/consents", consentH.Accept) protected.Get("/auth/consents", consentH.Status) + protected.Post("/debug/log", h.DebugLog) app.Get("/ws", ws.AuthMiddleware(authSvc), ws.Upgrade, ws.Handler(hub)) diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index efb3442..df620d7 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -1,6 +1,7 @@ package handlers import ( + "log/slog" "strings" "time" @@ -321,3 +322,30 @@ func age(birth *time.Time) *int { } return &a } + +// DebugLog — клиент-сайд диагностика (приходит из JS через api.js) +type debugLogReq struct { + Path string `json:"path"` + Status int `json:"status"` + Ms int `json:"ms"` + UA string `json:"ua"` + Err string `json:"err,omitempty"` + IsTelegram bool `json:"is_telegram"` +} + +func (h *Handlers) DebugLog(c *fiber.Ctx) error { + var req debugLogReq + if err := c.BodyParser(&req); err != nil { + return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "bad body"}) + } + slog.Info("client-debug", + "path", req.Path, + "status", req.Status, + "ms", req.Ms, + "is_tg", req.IsTelegram, + "ua", req.UA, + "err", req.Err, + "ip", c.IP(), + ) + return c.JSON(fiber.Map{"ok": true}) +}