Skip to content

Commit

Permalink
Fixed panic when loading spec with Domain on env which do not support…
Browse files Browse the repository at this point in the history
… custom domains

If Domain is non empty and enable_custom_domains is false, API router
becomes nil, and panics.

This was part of recent change to fix order of API loading. Restored
original behavior when default router picked as fallback.
  • Loading branch information
buger committed Nov 17, 2017
1 parent 2e9adec commit 83d9a52
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions api_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,15 @@ func loadApps(specs []*APISpec, muxer *mux.Router) {
for i, spec := range specs {
go func(spec *APISpec, i int) {
subrouter := hostRouters[spec.Domain]
if subrouter == nil {
log.WithFields(logrus.Fields{
"prefix": "main",
"domain": spec.Domain,
"api_id": spec.APIID,
}).Warning("Trying to load API with Domain when custom domains are disabled.")
subrouter = muxer
}

chainObj := processSpec(spec, apisByListen, redisStore, redisOrgStore, healthStore, rpcAuthStore, rpcOrgStore, subrouter)
chainObj.Index = i
chainChannel <- chainObj
Expand Down
25 changes: 25 additions & 0 deletions gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1182,3 +1182,28 @@ func TestMultiTargetProxy(t *testing.T) {
}
}
}

func TestCustomDomain(t *testing.T) {
t.Run("With custom domain support", func(t *testing.T) {
config.Global.EnableCustomDomains = true
defer func() {
config.Global.EnableCustomDomains = false
}()

buildAndLoadAPI(func(spec *APISpec) {
spec.Domain = "localhost"
},
func(spec *APISpec) {
spec.Domain = ""
})
})

t.Run("Without custom domain support", func(t *testing.T) {
buildAndLoadAPI(func(spec *APISpec) {
spec.Domain = "localhost"
},
func(spec *APISpec) {
spec.Domain = ""
})
})
}

0 comments on commit 83d9a52

Please sign in to comment.