A Traefik middleware plugin for dynamic URL redirection powered by Flecto.
This middleware intercepts HTTP requests and checks against a Flecto Manager to determine if requests should be redirected based on hostname and URI patterns.
Add the plugin to your Traefik static configuration:
experimental:
plugins:
flecto:
moduleName: github.com/flectolab/flecto-traefik-middleware
version: vX.X.XOr with TOML:
[experimental.plugins.flecto]
moduleName = "github.com/flectolab/flecto-traefik-middleware"
version = "vX.X.X"Use this configuration when all hosts use the same Flecto project:
http:
middlewares:
my-flecto-redirect:
plugin:
flecto:
manager_url: "https://flecto-manager.example.com"
namespace_code: "my-namespace"
project_code: "my-project"
token_jwt: "your-jwt-token"
header_authorization_name: "Authorization" # optional, default: Authorization
interval_check: "5m" # optional, default: 5m
agent_name: "my-traefik-agent" # optional, default: hostname
debug: false # optional, default: false
routers:
my-router:
rule: "Host(`example.com`)"
middlewares:
- my-flecto-redirect
service: my-serviceUse host_configs when you need different Flecto projects for different hosts:
http:
middlewares:
my-flecto-redirect:
plugin:
flecto:
# Parent configuration (shared settings)
manager_url: "https://flecto-manager.example.com"
namespace_code: "my-namespace"
token_jwt: "your-jwt-token"
interval_check: "5m"
debug: false
# project_code can be empty if host_configs is defined
# In this case, unmatched hosts will skip the middleware
host_configs:
# Minimal override: only project_code (required)
- hosts:
- "example.com"
- "example.fr"
project_code: "project-fr"
# Full override: all settings can be overridden
- hosts:
- "example.es"
manager_url: "https://other-manager.example.com"
namespace_code: "other-namespace"
project_code: "project-es"
token_jwt: "other-jwt-token"
header_authorization_name: "X-Custom-Auth"
interval_check: "10m"
routers:
my-router:
rule: "Host(`example.com`) || Host(`example.fr`) || Host(`example.es`)"
middlewares:
- my-flecto-redirect
service: my-service| Option | Required | Default | Description |
|---|---|---|---|
manager_url |
Yes | - | URL of the Flecto manager API |
namespace_code |
Yes | - | Namespace code in Flecto |
project_code |
Cond. | - | Project code in Flecto. Required if host_configs is not defined |
token_jwt |
Yes | - | JWT token for authentication with Flecto manager |
header_authorization_name |
No | Authorization |
HTTP header name for the JWT token |
interval_check |
No | 5m |
Interval to check for redirect rule updates |
agent_name |
No | hostname |
Name of this Traefik agent (for agent identification) |
debug |
No | false |
Add some headers (project version, url used and redirect matched) |
host_configs |
No | - | List of host-specific configurations (see below) |
| Option | Required | Inherited | Description |
|---|---|---|---|
hosts |
Yes | No | List of hostnames for this configuration |
project_code |
Yes | No | Project code in Flecto (cannot be inherited) |
manager_url |
No | Yes | Override the manager URL |
namespace_code |
No | Yes | Override the namespace code |
token_jwt |
No | Yes | Override the JWT token |
header_authorization_name |
No | Yes | Override the authorization header name |
interval_check |
No | Yes | Override the interval check duration |
Notes:
project_codeis always required in eachhost_configsentry and is never inherited from the parent configuration.agent_namecannot be overridden inhost_configsand is always inherited from the root configuration.
- The middleware connects to the Flecto manager on startup
- It periodically polls for redirect rule updates (configurable via
interval_check) - For each incoming request, it checks if the hostname and URI match any redirect rule
- If a match is found, the request is redirected with the appropriate HTTP status code (301, 302, 307, or 308)
- If no match is found, the request is passed to the next handler
When host_configs is defined:
- Each incoming request is matched against the configured hosts
- If a host matches, the corresponding project's client is used
- If no host matches and
project_codeis defined at the root level, the default client is used - If no host matches and
project_codeis not defined at the root level, the middleware is skipped and the request is passed to the next handler