Merge pull request #1538 from containous/merge-v1.2.3-master
Merge v1.2.3 master
This commit is contained in:
commit
5535318cda
6 changed files with 506 additions and 284 deletions
15
CHANGELOG.md
15
CHANGELOG.md
|
@ -1,5 +1,20 @@
|
|||
# Change Log
|
||||
|
||||
## [v1.2.3](https://github.com/containous/traefik/tree/v1.2.3) (2017-04-13)
|
||||
[Full Changelog](https://github.com/containous/traefik/compare/v1.2.2...v1.2.3)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Fix too many redirect [\#1433](https://github.com/containous/traefik/pull/1433) ([emilevauge](https://github.com/emilevauge))
|
||||
|
||||
## [v1.2.2](https://github.com/containous/traefik/tree/v1.2.2) (2017-04-11)
|
||||
[Full Changelog](https://github.com/containous/traefik/compare/v1.2.1...v1.2.2)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Carry PR 1271 [\#1417](https://github.com/containous/traefik/pull/1417) ([emilevauge](https://github.com/emilevauge))
|
||||
- Fix postloadconfig acme & Docker filter empty rule [\#1401](https://github.com/containous/traefik/pull/1401) ([emilevauge](https://github.com/emilevauge))
|
||||
|
||||
## [v1.2.1](https://github.com/containous/traefik/tree/v1.2.1) (2017-03-27)
|
||||
[Full Changelog](https://github.com/containous/traefik/compare/v1.2.0...v1.2.1)
|
||||
|
||||
|
|
|
@ -523,6 +523,11 @@ func (p *Provider) containerFilter(container dockerData) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
if len(p.getFrontendRule(container)) == 0 {
|
||||
log.Debugf("Filtering container with empty frontend rule %s", container.Name)
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -540,9 +545,11 @@ func (p *Provider) getFrontendRule(container dockerData) string {
|
|||
if labels, err := getLabels(container, []string{"com.docker.compose.project", "com.docker.compose.service"}); err == nil {
|
||||
return "Host:" + p.getSubDomain(labels["com.docker.compose.service"]+"."+labels["com.docker.compose.project"]) + "." + p.Domain
|
||||
}
|
||||
|
||||
if len(p.Domain) > 0 {
|
||||
return "Host:" + p.getSubDomain(container.ServiceName) + "." + p.Domain
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (p *Provider) getBackend(container dockerData) string {
|
||||
if label, err := getLabel(container, "traefik.backend"); err == nil {
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"github.com/containous/traefik/types"
|
||||
docker "github.com/docker/engine-api/types"
|
||||
"github.com/docker/engine-api/types/container"
|
||||
"github.com/docker/go-connections/nat"
|
||||
)
|
||||
|
||||
|
@ -489,125 +490,298 @@ func TestDockerGetLabels(t *testing.T) {
|
|||
func TestDockerTraefikFilter(t *testing.T) {
|
||||
containers := []struct {
|
||||
container docker.ContainerJSON
|
||||
exposedByDefault bool
|
||||
expected bool
|
||||
provider *Provider
|
||||
}{
|
||||
{
|
||||
container: containerJSON(),
|
||||
exposedByDefault: true,
|
||||
container: docker.ContainerJSON{
|
||||
ContainerJSONBase: &docker.ContainerJSONBase{
|
||||
Name: "container",
|
||||
},
|
||||
Config: &container.Config{},
|
||||
NetworkSettings: &docker.NetworkSettings{},
|
||||
},
|
||||
expected: false,
|
||||
provider: &Provider{
|
||||
Domain: "test",
|
||||
ExposedByDefault: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
container: containerJSON(
|
||||
labels(map[string]string{
|
||||
container: docker.ContainerJSON{
|
||||
ContainerJSONBase: &docker.ContainerJSONBase{
|
||||
Name: "container",
|
||||
},
|
||||
Config: &container.Config{
|
||||
Labels: map[string]string{
|
||||
"traefik.enable": "false",
|
||||
}),
|
||||
ports(nat.PortMap{
|
||||
},
|
||||
},
|
||||
NetworkSettings: &docker.NetworkSettings{
|
||||
NetworkSettingsBase: docker.NetworkSettingsBase{
|
||||
Ports: nat.PortMap{
|
||||
"80/tcp": {},
|
||||
}),
|
||||
),
|
||||
exposedByDefault: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
provider: &Provider{
|
||||
Domain: "test",
|
||||
ExposedByDefault: true,
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
container: containerJSON(
|
||||
labels(map[string]string{
|
||||
container: docker.ContainerJSON{
|
||||
ContainerJSONBase: &docker.ContainerJSONBase{
|
||||
Name: "container",
|
||||
},
|
||||
Config: &container.Config{
|
||||
Labels: map[string]string{
|
||||
"traefik.frontend.rule": "Host:foo.bar",
|
||||
}),
|
||||
ports(nat.PortMap{
|
||||
},
|
||||
},
|
||||
NetworkSettings: &docker.NetworkSettings{
|
||||
NetworkSettingsBase: docker.NetworkSettingsBase{
|
||||
Ports: nat.PortMap{
|
||||
"80/tcp": {},
|
||||
}),
|
||||
),
|
||||
exposedByDefault: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
provider: &Provider{
|
||||
Domain: "test",
|
||||
ExposedByDefault: true,
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
container: containerJSON(
|
||||
ports(nat.PortMap{
|
||||
container: docker.ContainerJSON{
|
||||
ContainerJSONBase: &docker.ContainerJSONBase{
|
||||
Name: "container-multi-ports",
|
||||
},
|
||||
Config: &container.Config{},
|
||||
NetworkSettings: &docker.NetworkSettings{
|
||||
NetworkSettingsBase: docker.NetworkSettingsBase{
|
||||
Ports: nat.PortMap{
|
||||
"80/tcp": {},
|
||||
"443/tcp": {},
|
||||
}),
|
||||
),
|
||||
exposedByDefault: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
provider: &Provider{
|
||||
Domain: "test",
|
||||
ExposedByDefault: true,
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
container: containerJSON(
|
||||
ports(nat.PortMap{
|
||||
container: docker.ContainerJSON{
|
||||
ContainerJSONBase: &docker.ContainerJSONBase{
|
||||
Name: "container",
|
||||
},
|
||||
Config: &container.Config{},
|
||||
NetworkSettings: &docker.NetworkSettings{
|
||||
NetworkSettingsBase: docker.NetworkSettingsBase{
|
||||
Ports: nat.PortMap{
|
||||
"80/tcp": {},
|
||||
}),
|
||||
),
|
||||
exposedByDefault: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
provider: &Provider{
|
||||
Domain: "test",
|
||||
ExposedByDefault: true,
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
container: containerJSON(
|
||||
labels(map[string]string{
|
||||
container: docker.ContainerJSON{
|
||||
ContainerJSONBase: &docker.ContainerJSONBase{
|
||||
Name: "container",
|
||||
},
|
||||
Config: &container.Config{
|
||||
Labels: map[string]string{
|
||||
"traefik.port": "80",
|
||||
}),
|
||||
ports(nat.PortMap{
|
||||
},
|
||||
},
|
||||
NetworkSettings: &docker.NetworkSettings{
|
||||
NetworkSettingsBase: docker.NetworkSettingsBase{
|
||||
Ports: nat.PortMap{
|
||||
"80/tcp": {},
|
||||
"443/tcp": {},
|
||||
}),
|
||||
),
|
||||
exposedByDefault: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
provider: &Provider{
|
||||
Domain: "test",
|
||||
ExposedByDefault: true,
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
container: containerJSON(
|
||||
labels(map[string]string{
|
||||
container: docker.ContainerJSON{
|
||||
ContainerJSONBase: &docker.ContainerJSONBase{
|
||||
Name: "container",
|
||||
},
|
||||
Config: &container.Config{
|
||||
Labels: map[string]string{
|
||||
"traefik.enable": "true",
|
||||
}),
|
||||
ports(nat.PortMap{
|
||||
},
|
||||
},
|
||||
NetworkSettings: &docker.NetworkSettings{
|
||||
NetworkSettingsBase: docker.NetworkSettingsBase{
|
||||
Ports: nat.PortMap{
|
||||
"80/tcp": {},
|
||||
}),
|
||||
),
|
||||
exposedByDefault: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
provider: &Provider{
|
||||
Domain: "test",
|
||||
ExposedByDefault: true,
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
container: containerJSON(
|
||||
labels(map[string]string{
|
||||
container: docker.ContainerJSON{
|
||||
ContainerJSONBase: &docker.ContainerJSONBase{
|
||||
Name: "container",
|
||||
},
|
||||
Config: &container.Config{
|
||||
Labels: map[string]string{
|
||||
"traefik.enable": "anything",
|
||||
}),
|
||||
ports(nat.PortMap{
|
||||
},
|
||||
},
|
||||
NetworkSettings: &docker.NetworkSettings{
|
||||
NetworkSettingsBase: docker.NetworkSettingsBase{
|
||||
Ports: nat.PortMap{
|
||||
"80/tcp": {},
|
||||
}),
|
||||
),
|
||||
exposedByDefault: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
provider: &Provider{
|
||||
Domain: "test",
|
||||
ExposedByDefault: true,
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
container: containerJSON(
|
||||
labels(map[string]string{
|
||||
container: docker.ContainerJSON{
|
||||
ContainerJSONBase: &docker.ContainerJSONBase{
|
||||
Name: "container",
|
||||
},
|
||||
Config: &container.Config{
|
||||
Labels: map[string]string{
|
||||
"traefik.frontend.rule": "Host:foo.bar",
|
||||
}),
|
||||
ports(nat.PortMap{
|
||||
},
|
||||
},
|
||||
NetworkSettings: &docker.NetworkSettings{
|
||||
NetworkSettingsBase: docker.NetworkSettingsBase{
|
||||
Ports: nat.PortMap{
|
||||
"80/tcp": {},
|
||||
}),
|
||||
),
|
||||
exposedByDefault: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
provider: &Provider{
|
||||
Domain: "test",
|
||||
ExposedByDefault: true,
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
container: containerJSON(
|
||||
ports(nat.PortMap{
|
||||
container: docker.ContainerJSON{
|
||||
ContainerJSONBase: &docker.ContainerJSONBase{
|
||||
Name: "container",
|
||||
},
|
||||
Config: &container.Config{},
|
||||
NetworkSettings: &docker.NetworkSettings{
|
||||
NetworkSettingsBase: docker.NetworkSettingsBase{
|
||||
Ports: nat.PortMap{
|
||||
"80/tcp": {},
|
||||
}),
|
||||
),
|
||||
exposedByDefault: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
provider: &Provider{
|
||||
Domain: "test",
|
||||
ExposedByDefault: false,
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
container: containerJSON(
|
||||
labels(map[string]string{
|
||||
container: docker.ContainerJSON{
|
||||
ContainerJSONBase: &docker.ContainerJSONBase{
|
||||
Name: "container",
|
||||
},
|
||||
Config: &container.Config{
|
||||
Labels: map[string]string{
|
||||
"traefik.enable": "true",
|
||||
}),
|
||||
ports(nat.PortMap{
|
||||
},
|
||||
},
|
||||
NetworkSettings: &docker.NetworkSettings{
|
||||
NetworkSettingsBase: docker.NetworkSettingsBase{
|
||||
Ports: nat.PortMap{
|
||||
"80/tcp": {},
|
||||
}),
|
||||
),
|
||||
exposedByDefault: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
provider: &Provider{
|
||||
Domain: "test",
|
||||
ExposedByDefault: false,
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
container: docker.ContainerJSON{
|
||||
ContainerJSONBase: &docker.ContainerJSONBase{
|
||||
Name: "container",
|
||||
},
|
||||
Config: &container.Config{
|
||||
Labels: map[string]string{
|
||||
"traefik.enable": "true",
|
||||
},
|
||||
},
|
||||
NetworkSettings: &docker.NetworkSettings{
|
||||
NetworkSettingsBase: docker.NetworkSettingsBase{
|
||||
Ports: nat.PortMap{
|
||||
"80/tcp": {},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
provider: &Provider{
|
||||
ExposedByDefault: false,
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
container: docker.ContainerJSON{
|
||||
ContainerJSONBase: &docker.ContainerJSONBase{
|
||||
Name: "container",
|
||||
},
|
||||
Config: &container.Config{
|
||||
Labels: map[string]string{
|
||||
"traefik.enable": "true",
|
||||
"traefik.frontend.rule": "Host:i.love.this.host",
|
||||
},
|
||||
},
|
||||
NetworkSettings: &docker.NetworkSettings{
|
||||
NetworkSettingsBase: docker.NetworkSettingsBase{
|
||||
Ports: nat.PortMap{
|
||||
"80/tcp": {},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
provider: &Provider{
|
||||
ExposedByDefault: false,
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
}
|
||||
|
@ -616,12 +790,10 @@ func TestDockerTraefikFilter(t *testing.T) {
|
|||
e := e
|
||||
t.Run(strconv.Itoa(containerID), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
provider := Provider{}
|
||||
provider.ExposedByDefault = e.exposedByDefault
|
||||
dockerData := parseContainer(e.container)
|
||||
actual := provider.containerFilter(dockerData)
|
||||
actual := e.provider.containerFilter(dockerData)
|
||||
if actual != e.expected {
|
||||
t.Errorf("expected %v for %+v (%+v, %+v), got %+v", e.expected, e.container, e.container.NetworkSettings, e.container.ContainerJSONBase, actual)
|
||||
t.Errorf("expected %v for %+v, got %+v", e.expected, e, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ func TestDockerGetServiceFrontendRule(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
container: containerJSON(name("foo")),
|
||||
expected: "Host:foo.",
|
||||
expected: "",
|
||||
},
|
||||
{
|
||||
container: containerJSON(labels(map[string]string{
|
||||
|
|
|
@ -504,85 +504,121 @@ func TestSwarmGetLabels(t *testing.T) {
|
|||
func TestSwarmTraefikFilter(t *testing.T) {
|
||||
services := []struct {
|
||||
service swarm.Service
|
||||
exposedByDefault bool
|
||||
expected bool
|
||||
networks map[string]*docker.NetworkResource
|
||||
provider *Provider
|
||||
}{
|
||||
{
|
||||
service: swarmService(),
|
||||
exposedByDefault: true,
|
||||
expected: false,
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
provider: &Provider{
|
||||
SwarmMode: true,
|
||||
Domain: "test",
|
||||
ExposedByDefault: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
service: swarmService(serviceLabels(map[string]string{
|
||||
"traefik.enable": "false",
|
||||
"traefik.port": "80",
|
||||
})),
|
||||
exposedByDefault: true,
|
||||
expected: false,
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
provider: &Provider{
|
||||
SwarmMode: true,
|
||||
Domain: "test",
|
||||
ExposedByDefault: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
service: swarmService(serviceLabels(map[string]string{
|
||||
"traefik.frontend.rule": "Host:foo.bar",
|
||||
"traefik.port": "80",
|
||||
})),
|
||||
exposedByDefault: true,
|
||||
expected: true,
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
provider: &Provider{
|
||||
SwarmMode: true,
|
||||
Domain: "test",
|
||||
ExposedByDefault: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
service: swarmService(serviceLabels(map[string]string{
|
||||
"traefik.port": "80",
|
||||
})),
|
||||
exposedByDefault: true,
|
||||
expected: true,
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
provider: &Provider{
|
||||
SwarmMode: true,
|
||||
Domain: "test",
|
||||
ExposedByDefault: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
service: swarmService(serviceLabels(map[string]string{
|
||||
"traefik.enable": "true",
|
||||
"traefik.port": "80",
|
||||
})),
|
||||
exposedByDefault: true,
|
||||
expected: true,
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
provider: &Provider{
|
||||
SwarmMode: true,
|
||||
Domain: "test",
|
||||
ExposedByDefault: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
service: swarmService(serviceLabels(map[string]string{
|
||||
"traefik.enable": "anything",
|
||||
"traefik.port": "80",
|
||||
})),
|
||||
exposedByDefault: true,
|
||||
expected: true,
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
provider: &Provider{
|
||||
SwarmMode: true,
|
||||
Domain: "test",
|
||||
ExposedByDefault: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
service: swarmService(serviceLabels(map[string]string{
|
||||
"traefik.frontend.rule": "Host:foo.bar",
|
||||
"traefik.port": "80",
|
||||
})),
|
||||
exposedByDefault: true,
|
||||
expected: true,
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
provider: &Provider{
|
||||
SwarmMode: true,
|
||||
Domain: "test",
|
||||
ExposedByDefault: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
service: swarmService(serviceLabels(map[string]string{
|
||||
"traefik.port": "80",
|
||||
})),
|
||||
exposedByDefault: false,
|
||||
expected: false,
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
provider: &Provider{
|
||||
SwarmMode: true,
|
||||
Domain: "test",
|
||||
ExposedByDefault: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
service: swarmService(serviceLabels(map[string]string{
|
||||
"traefik.enable": "true",
|
||||
"traefik.port": "80",
|
||||
})),
|
||||
exposedByDefault: false,
|
||||
expected: true,
|
||||
networks: map[string]*docker.NetworkResource{},
|
||||
provider: &Provider{
|
||||
SwarmMode: true,
|
||||
Domain: "test",
|
||||
ExposedByDefault: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -591,11 +627,7 @@ func TestSwarmTraefikFilter(t *testing.T) {
|
|||
t.Run(strconv.Itoa(serviceID), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
dockerData := parseService(e.service, e.networks)
|
||||
provider := &Provider{
|
||||
SwarmMode: true,
|
||||
}
|
||||
provider.ExposedByDefault = e.exposedByDefault
|
||||
actual := provider.containerFilter(dockerData)
|
||||
actual := e.provider.containerFilter(dockerData)
|
||||
if actual != e.expected {
|
||||
t.Errorf("expected %v for %+v, got %+v", e.expected, e, actual)
|
||||
}
|
||||
|
|
|
@ -315,15 +315,16 @@ func (server *Server) postLoadConfig() {
|
|||
for _, frontend := range configuration.Frontends {
|
||||
|
||||
// check if one of the frontend entrypoints is configured with TLS
|
||||
TLSEnabled := false
|
||||
// and is configured with ACME
|
||||
ACMEEnabled := false
|
||||
for _, entrypoint := range frontend.EntryPoints {
|
||||
if server.globalConfiguration.EntryPoints[entrypoint].TLS != nil {
|
||||
TLSEnabled = true
|
||||
if server.globalConfiguration.ACME.EntryPoint == entrypoint && server.globalConfiguration.EntryPoints[entrypoint].TLS != nil {
|
||||
ACMEEnabled = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if TLSEnabled {
|
||||
if ACMEEnabled {
|
||||
for _, route := range frontend.Routes {
|
||||
rules := Rules{}
|
||||
domains, err := rules.ParseDomains(route.Rule)
|
||||
|
@ -547,13 +548,11 @@ func (server *Server) buildEntryPoints(globalConfiguration GlobalConfiguration)
|
|||
// provider configurations.
|
||||
func (server *Server) loadConfig(configurations configs, globalConfiguration GlobalConfiguration) (map[string]*serverEntryPoint, error) {
|
||||
serverEntryPoints := server.buildEntryPoints(globalConfiguration)
|
||||
redirectHandlers := make(map[string]http.Handler)
|
||||
|
||||
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:
|
||||
|
@ -595,19 +594,20 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo
|
|||
}
|
||||
|
||||
entryPoint := globalConfiguration.EntryPoints[entryPointName]
|
||||
negroni := negroni.New()
|
||||
if entryPoint.Redirect != nil {
|
||||
if redirectHandlers[entryPointName] != nil {
|
||||
newServerRoute.route.Handler(redirectHandlers[entryPointName])
|
||||
negroni.Use(redirectHandlers[entryPointName])
|
||||
} else if handler, err := server.loadEntryPointConfig(entryPointName, entryPoint); err != nil {
|
||||
log.Errorf("Error loading entrypoint configuration for frontend %s: %v", frontendName, err)
|
||||
log.Errorf("Skipping frontend %s...", frontendName)
|
||||
continue frontend
|
||||
} else {
|
||||
newServerRoute.route.Handler(handler)
|
||||
negroni.Use(handler)
|
||||
redirectHandlers[entryPointName] = handler
|
||||
}
|
||||
} else {
|
||||
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)
|
||||
|
@ -715,14 +715,12 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo
|
|||
log.Debugf("Creating retries max attempts %d", retries)
|
||||
}
|
||||
|
||||
var negroni = negroni.New()
|
||||
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))
|
||||
negroni.Use(metricsMiddlewareBackend)
|
||||
}
|
||||
}
|
||||
|
||||
if len(frontend.BasicAuth) > 0 {
|
||||
users := types.Users{}
|
||||
for _, user := range frontend.BasicAuth {
|
||||
|
@ -739,7 +737,6 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo
|
|||
}
|
||||
negroni.Use(authMiddleware)
|
||||
}
|
||||
|
||||
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))
|
||||
|
@ -752,15 +749,15 @@ 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 {
|
||||
log.Errorf("Error building route: %s", err)
|
||||
|
@ -810,7 +807,7 @@ func (server *Server) wireFrontendBackend(serverRoute *serverRoute, handler http
|
|||
serverRoute.route.Handler(handler)
|
||||
}
|
||||
|
||||
func (server *Server) loadEntryPointConfig(entryPointName string, entryPoint *EntryPoint) (http.Handler, error) {
|
||||
func (server *Server) loadEntryPointConfig(entryPointName string, entryPoint *EntryPoint) (negroni.Handler, error) {
|
||||
regex := entryPoint.Redirect.Regex
|
||||
replacement := entryPoint.Redirect.Replacement
|
||||
if len(entryPoint.Redirect.EntryPoint) > 0 {
|
||||
|
@ -834,9 +831,8 @@ func (server *Server) loadEntryPointConfig(entryPointName string, entryPoint *En
|
|||
return nil, err
|
||||
}
|
||||
log.Debugf("Creating entryPoint redirect %s -> %s : %s -> %s", entryPointName, entryPoint.Redirect.EntryPoint, regex, replacement)
|
||||
negroni := negroni.New()
|
||||
negroni.Use(rewrite)
|
||||
return negroni, nil
|
||||
|
||||
return rewrite, nil
|
||||
}
|
||||
|
||||
func (server *Server) buildDefaultHTTPRouter() *mux.Router {
|
||||
|
|
Loading…
Add table
Reference in a new issue