From 65350e3acb456969a9d61bd6568ef27650b7daa7 Mon Sep 17 00:00:00 2001 From: Jonas Kaninda Date: Fri, 29 Nov 2024 16:41:05 +0100 Subject: [PATCH] fix: Sort routes by path in descending order for better proxying --- internal/routes.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/routes.go b/internal/routes.go index 7bd8abe..0562d96 100644 --- a/internal/routes.go +++ b/internal/routes.go @@ -24,6 +24,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" "slices" + "sort" ) // init initializes prometheus metrics @@ -64,6 +65,10 @@ func (gatewayServer GatewayServer) Initialize() *mux.Router { if len(gateway.Redis.Addr) != 0 { redisBased = true } + // Sort routes by path in descending order + sort.Slice(dynamicRoutes, func(i, j int) bool { + return len(dynamicRoutes[i].Path) > len(dynamicRoutes[j].Path) + }) // Routes background healthcheck routesHealthCheck(dynamicRoutes)