fix: Sort routes by path in descending order for better proxying

This commit is contained in:
Jonas Kaninda
2024-11-29 16:41:05 +01:00
parent 1c6457e7a0
commit 65350e3acb

View File

@@ -24,6 +24,7 @@ import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
"slices" "slices"
"sort"
) )
// init initializes prometheus metrics // init initializes prometheus metrics
@@ -64,6 +65,10 @@ func (gatewayServer GatewayServer) Initialize() *mux.Router {
if len(gateway.Redis.Addr) != 0 { if len(gateway.Redis.Addr) != 0 {
redisBased = true 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 // Routes background healthcheck
routesHealthCheck(dynamicRoutes) routesHealthCheck(dynamicRoutes)