Merge pull request #141 from jkaninda/refactor

fix: Sort routes by path in descending order for better proxying
This commit is contained in:
2024-11-29 16:42:27 +01:00
committed by GitHub

View File

@@ -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)