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}) +}