This Traefik middleware validates requests against an Unleash (feature flag) server and rewrites the path, headers and host of the request based on input parameters defined in the YAML configuration file.
Follow the Traefik instructions for installing plugins.
To configure this middleware, you need to define the parameters in the dynamic.yml
file.
Parameter | Type | Required | Description |
---|---|---|---|
url | string | Yes | URL of the Unleash server |
app | string | Yes | Name of the application in Unleash |
interval | int | No | Update interval in seconds |
metrics.interval | int | No | Metrics reporting interval in seconds |
toggles | list | Yes | List of feature flag toggles |
toggles[].feature | string | Yes | Name of the feature flag |
toggles[].pathRewrite.pathMatcher | string | No | Path to be validated |
toggles[].pathRewrite.rewriteRule | string | No | Path to redirect to if the feature flag is active |
toggles[].hostRewrite.hostMatcher | string | No | Host to be validated |
toggles[].hostRewrite.rewriteRule | string | No | Host to redirect to if the feature flag is active |
toggles[].headerModifers | list | No | List of headers to be added to the request or response |
toggles[].headerModifiers[].headerName | string | Yes | Header key |
toggles[].headerModifiers[].headerValue | string | Yes | Header value |
toggles[].headerModifiers[].context | string | Yes | Context of the header (either "request" or "response") |
offlineMode | boolean | No | The plugin is configured in local mode without external dependencies |
Define the configuration in the dynamic.yml
file:
unleash:url: "http://unleash:4242/api/"app: "test-app"interval: 10metrics:interval: 10toggles:- feature: "test-toggle-user-id"pathRewrite:pathMatcher: "/foo"rewriteRule: "/bar"hostRewrite:hostMatcher: "localhost"rewriteRule: "whoami2"- feature: "test-toggle"pathRewrite:pathMatcher: "/bar"rewriteRule: "/foo"hostRewrite:hostMatcher: "localhost"rewriteRule: "whoami2"- feature: "test-toggle-path"pathRewrite:pathMatcher: "/john"rewriteRule: "/doe"- feature: "test-toggle-host"hostRewrite:hostMatcher: "localhost"rewriteRule: "whoami1"
Apply the middleware to your routers in the Traefik configuration:
http:routers:my-router:rule: "Host(`example.com`)"service: "my-service"middlewares:- "unleash"
Here is a complete configuration example:
http:routers:my-router:rule: "Host(`example.com`)"service: "my-service"middlewares:- "unleash"middlewares:unleash:plugin:unleash:url: "http://unleash:4242/api/"app: "test-app"interval: 10metrics:interval: 10toggles:- feature: "test-toggle-user-id"pathRewrite:pathMatcher: "/foo"rewriteRule: "/bar"hostRewrite:hostMatcher: "localhost"rewriteRule: "whoami2"headerModifiers:- headerName: "X-Foo"headerValue: "Bar"context: "request"- headerName: "X-Served-By"headerValue: "whoami2"context: "response"- feature: "test-toggle"pathRewrite:pathMatcher: "/bar"rewriteRule: "/foo"hostRewrite:value: "localhost"rewrite: "whoami2"- feature: "test-toggle-path"pathRewrite:pathMatcher: "/john"rewriteRule: "/doe"- feature: "test-toggle-host"hostRewrite:hostMatcher: "localhost"rewriteRule: "whoami1"
Contributions are welcome! If you want to contribute, please open an issue or a pull request in this repository.
This project is licensed under the MIT License.