Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TT-13507] Fix for custom domains with substring listen path #6705

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions docker/services/httpbin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
services:
httpbin:
image: tykio/ci-tools:latest
platform: linux/amd64
networks:
- proxy
ports:
Expand Down
23 changes: 15 additions & 8 deletions gateway/api_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -924,21 +924,28 @@ func (gw *Gateway) loadGraphQLPlayground(spec *APISpec, subrouter *mux.Router) {
})
}

func sortSpecsByListenPath(specs []*APISpec) {
// sort by listen path from longer to shorter, so that /foo
// doesn't break /foo-bar
sort.Slice(specs, func(i, j int) bool {
// we sort by the following rules:
// - decreasing order of listen path length
// - if a domain is empty it should be at the end
if (specs[i].Domain == "") != (specs[j].Domain == "") {
return specs[i].Domain != ""
}
return len(specs[i].Proxy.ListenPath) > len(specs[j].Proxy.ListenPath)
})
}

// Create the individual API (app) specs based on live configurations and assign middleware
func (gw *Gateway) loadApps(specs []*APISpec) {
mainLog.Info("Loading API configurations.")

tmpSpecRegister := make(map[string]*APISpec)
tmpSpecHandles := new(sync.Map)

// sort by listen path from longer to shorter, so that /foo
// doesn't break /foo-bar
sort.Slice(specs, func(i, j int) bool {
if specs[i].Domain != specs[j].Domain {
return len(specs[i].Domain) > len(specs[j].Domain)
}
return len(specs[i].Proxy.ListenPath) > len(specs[j].Proxy.ListenPath)
})
sortSpecsByListenPath(specs)

// Create a new handler for each API spec
apisByListen := countApisByListenHash(specs)
Expand Down
Loading
Loading