From 1c4ec0e4fe4a765dad1db9ab332ebfdcc8c2b11e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Herg=C3=A8s?= Date: Tue, 30 Dec 2025 18:59:30 +0100 Subject: feat(storage): scope stats per ip instead of target --- backend/router.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'backend/router.go') diff --git a/backend/router.go b/backend/router.go index 0a58b26..e11db94 100644 --- a/backend/router.go +++ b/backend/router.go @@ -25,7 +25,6 @@ const ( assetsFSKey = "assets_fs" debugKey = "debug" loginKey = "login" - ipAdressKey = "ip_adress" ) //go:embed templates @@ -80,7 +79,10 @@ func NewRouter(debug bool, cfg *Config, db *sql.DB, assets fs.FS) *chi.Mux { if ip == "" { ip = r.RemoteAddr } - ctx = context.WithValue(ctx, ipAdressKey, ip) + if strings.Contains(ip, ":") { + ip = strings.Split(ip, ":")[0] + } + ctx = context.WithValue(ctx, storage.IPAddressKey, ip) ctx = context.WithValue(ctx, configKey, cfg) ctx = context.WithValue(ctx, assetsFSKey, assets) ctx = context.WithValue(ctx, debugKey, debug) @@ -119,9 +121,12 @@ func NewRouter(debug bool, cfg *Config, db *sql.DB, assets fs.FS) *chi.Mux { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { next.ServeHTTP(w, r) go func(ctx context.Context, r *http.Request) { + if strings.HasPrefix(r.RequestURI, "/static") { + return + } statusCode := GetStatusCode(ctx)() logger := GetLogger(ctx) - if statusCode >= 299 { + if statusCode >= 299 && r.RequestURI != storage.HumanPageLoad { logger.Debug("not updating stats for status code above 299", "status", statusCode) return } -- cgit v1.2.3