containous / traefik-extra-service-fabric

Traefik extra: Service Fabric Provider
Apache License 2.0
12 stars 14 forks source link

Support for multiple front-end rule sets #37

Closed reddogaw closed 6 years ago

reddogaw commented 6 years ago

We require multiple front-end rule sets to be accessible for our Fabric Service. At the moment, it appears that additional traefik.frontend.rule{.name} labels will AND themselves together instead of OR.

My StackOverflow question should detail our use-case.

Another use case example would be to support multiple host names for our service.

Suggested label syntax could be something like this:

  <Extensions>
    <Extension Name="Traefik">
      <Labels xmlns="http://schemas.microsoft.com/2015/03/fabact-no-schema">
        <Label Key="traefik.frontends">local; external</Label> <!-- Identifies the names for multiple frontends support -->
        <Label Key="traefik.frontend.local.rule">PathPrefixStrip: /my-service/</Label> <!-- Defines default rule for "local" frontend -->
        <Label Key="traefik.frontend.external.rule">Host: my-domain.localhost</Label> <!-- Defines default rule for "external" frontend -->
        <Label Key="traefik.frontends.passHostHeader">true</Label> <!-- Due to "frontends" it applies to all frontends -->
        <Label Key="traefik.frontend.external.passHostHeader">false</Label> <!-- Overrides the "frontends" rule for the "external" frontend -->
        <Label Key="traefik.enable">true</Label>
      </Labels>
    </Extension>
  </Extensions>
ldez commented 6 years ago

With Traefik, you can only combine multiple rules with an AND: https://docs.traefik.io/v1.6/basics/#combining-multiple-rules

https://github.com/containous/traefik/issues/3026

reddogaw commented 6 years ago

Yes, with Traefik rules will be AND-ed together for a single front-end. However, you can definitely define multiple front-ends which point at the same backend so that the rules for each front-end are effectively OR-ed together.

This was intended as a feature request.

For example, I can achieve this using the [file] provider:

[frontends]
  [frontends.frontend1]
  backend = "backend1"
  passHostHeader = true
    [frontends.frontend1.routes.public]
    rule = "Host:mydomain.localhost"
  [frontends.frontend2]
  backend = "backend1"
  passHostHeader = true
    [frontends.frontend2.routes.internal]
    rule = "Host:localhost;PathPrefixStrip:/test/"
ldez commented 6 years ago

You can use a custom template if you want to automate this behavior:

[serviceFabric]

# Override default configuration template.
# For advanced users :)
#
# Optional
#
filename = "servicefabric.tmpl"