Fix too many redirect

Signed-off-by: Emile Vauge <emile@vauge.com>
This commit is contained in:
Emile Vauge 2017-04-13 16:37:07 +02:00
parent ca9e36ebe3
commit e7a73d3fb3
No known key found for this signature in database
GPG key ID: D808B4C167352E59

View file

@ -549,12 +549,10 @@ func (server *Server) buildEntryPoints(globalConfiguration GlobalConfiguration)
func (server *Server) loadConfig(configurations configs, globalConfiguration GlobalConfiguration) (map[string]*serverEntryPoint, error) {
serverEntryPoints := server.buildEntryPoints(globalConfiguration)
redirectHandlers := make(map[string]negroni.Handler)
backends := map[string]http.Handler{}
backendsHealthcheck := map[string]*healthcheck.BackendHealthCheck{}
backend2FrontendMap := map[string]string{}
for _, configuration := range configurations {
frontendNames := sortedFrontendNamesForConfig(configuration)
frontend:
@ -609,7 +607,7 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo
redirectHandlers[entryPointName] = handler
}
}
if backends[frontend.Backend] == nil {
if backends[entryPointName+frontend.Backend] == nil {
log.Debugf("Creating backend %s", frontend.Backend)
var lb http.Handler
rr, _ := roundrobin.New(saveBackend)
@ -717,7 +715,6 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo
log.Debugf("Creating retries max attempts %d", retries)
}
if server.globalConfiguration.Web != nil && server.globalConfiguration.Web.Metrics != nil {
if server.globalConfiguration.Web.Metrics.Prometheus != nil {
metricsMiddlewareBackend := middlewares.NewMetricsWrapper(middlewares.NewPrometheus(frontend.Backend, server.globalConfiguration.Web.Metrics.Prometheus))
@ -739,7 +736,8 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo
log.Fatal("Error creating Auth: ", err)
}
negroni.Use(authMiddleware)
} if configuration.Backends[frontend.Backend].CircuitBreaker != nil {
}
if configuration.Backends[frontend.Backend].CircuitBreaker != nil {
log.Debugf("Creating circuit breaker %s", configuration.Backends[frontend.Backend].CircuitBreaker.Expression)
cbreaker, err := middlewares.NewCircuitBreaker(lb, configuration.Backends[frontend.Backend].CircuitBreaker.Expression, cbreaker.Logger(oxyLogger))
if err != nil {
@ -751,14 +749,14 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo
} else {
negroni.UseHandler(lb)
}
backends[frontend.Backend] = negroni
backends[entryPointName+frontend.Backend] = negroni
} else {
log.Debugf("Reusing backend %s", frontend.Backend)
}
if frontend.Priority > 0 {
newServerRoute.route.Priority(frontend.Priority)
}
server.wireFrontendBackend(newServerRoute, backends[frontend.Backend])
server.wireFrontendBackend(newServerRoute, backends[entryPointName+frontend.Backend])
err := newServerRoute.route.GetError()
if err != nil {