https://github.com/slimani-dev/dynamichost
DynamicHost - A Custom Traefik Middleware Plugin
https://github.com/slimani-dev/dynamichost
Last synced: 11 months ago
JSON representation
DynamicHost - A Custom Traefik Middleware Plugin
- Host: GitHub
- URL: https://github.com/slimani-dev/dynamichost
- Owner: slimani-dev
- License: apache-2.0
- Created: 2025-03-08T15:09:23.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-03-08T16:48:29.000Z (over 1 year ago)
- Last Synced: 2025-03-08T17:20:55.714Z (over 1 year ago)
- Language: Go
- Size: 139 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# DynamicHost Plugin for Traefik
[](https://github.com/yourusername/dynamichost-plugin/actions)
The `DynamicHost` plugin is a middleware for [Traefik](https://traefik.io) that dynamically rewrites the host header based on a regex pattern. This allows flexible host transformation based on request attributes.
## Features
- Uses a regex pattern to match and transform the host dynamically.
- Allows custom host structures for different incoming requests.
- Fully compatible with Traefik's middleware system.
## Configuration
To use the `DynamicHost` plugin, you must define it in the **static configuration** of Traefik:
```yaml
# Static configuration
experimental:
plugins:
dynamichost:
moduleName: github.com/slimani-dev/dynamichost
version: v0.1.0
```
Then, you can configure it dynamically:
```yaml
# Dynamic configuration
http:
routers:
my-router:
rule: Host(`example.localhost`)
service: my-service
entryPoints:
- web
middlewares:
- dynamic-host
services:
my-service:
loadBalancer:
servers:
- url: http://127.0.0.1:8080
middlewares:
dynamic-host:
plugin:
dynamichost:
regexPattern: "^([^.]+)\\.localhost$"
newHost: "$1.example.com"
```
### Parameters
| Parameter | Type | Description |
|----------------|--------|-------------|
| `regexPattern` | string | The regex pattern used to match the original host. |
| `newHost` | string | The new host format using regex capture groups. |
### Example Behavior
| Incoming Host | Transformed Host |
|-------------------|------------------|
| `abc.localhost` | `abc.example.com` |
| `test.localhost` | `test.example.com` |
## License
This project is licensed under the MIT License.