feat: magic for traefik redirectregex in services
This commit is contained in:
parent
c770c8d988
commit
dfba593072
@ -222,7 +222,8 @@ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_
|
||||
|
||||
$basic_auth = false;
|
||||
$basic_auth_middleware = null;
|
||||
|
||||
$redirect = false;
|
||||
$redirect_middleware = null;
|
||||
if ($serviceLabels) {
|
||||
$basic_auth = $serviceLabels->contains(function ($value) {
|
||||
return str_contains($value, 'basicauth');
|
||||
@ -237,6 +238,19 @@ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_
|
||||
->filter()
|
||||
->first();
|
||||
}
|
||||
$redirect = $serviceLabels->contains(function ($value) {
|
||||
return str_contains($value, 'redirectregex');
|
||||
});
|
||||
if ($redirect) {
|
||||
$redirect_middleware = $serviceLabels
|
||||
->map(function ($item) {
|
||||
if (preg_match('/traefik\.http\.middlewares\.(.*?)\.redirectregex\.regex/', $item, $matches)) {
|
||||
return $matches[1];
|
||||
}
|
||||
})
|
||||
->filter()
|
||||
->first();
|
||||
}
|
||||
}
|
||||
foreach ($domains as $loop => $domain) {
|
||||
try {
|
||||
@ -266,12 +280,18 @@ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_
|
||||
if ($basic_auth && $basic_auth_middleware) {
|
||||
$middlewares = $middlewares . ',' . $basic_auth_middleware;
|
||||
}
|
||||
if ($redirect && $redirect_middleware) {
|
||||
$middlewares = $middlewares . ',' . $redirect_middleware;
|
||||
}
|
||||
$labels->push("traefik.http.routers.{$https_label}.middlewares={$middlewares}");
|
||||
} else {
|
||||
$middlewares = "gzip";
|
||||
if ($basic_auth && $basic_auth_middleware) {
|
||||
$middlewares = $middlewares . ',' . $basic_auth_middleware;
|
||||
}
|
||||
if ($redirect && $redirect_middleware) {
|
||||
$middlewares = $middlewares . ',' . $redirect_middleware;
|
||||
}
|
||||
$labels->push("traefik.http.routers.{$https_label}.middlewares={$middlewares}");
|
||||
}
|
||||
$labels->push("traefik.http.routers.{$https_label}.tls=true");
|
||||
@ -301,12 +321,18 @@ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_
|
||||
if ($basic_auth && $basic_auth_middleware) {
|
||||
$middlewares = $middlewares . ',' . $basic_auth_middleware;
|
||||
}
|
||||
if ($redirect && $redirect_middleware) {
|
||||
$middlewares = $middlewares . ',' . $redirect_middleware;
|
||||
}
|
||||
$labels->push("traefik.http.routers.{$http_label}.middlewares={$middlewares}");
|
||||
} else {
|
||||
$middlewares = "gzip";
|
||||
if ($basic_auth && $basic_auth_middleware) {
|
||||
$middlewares = $middlewares . ',' . $basic_auth_middleware;
|
||||
}
|
||||
if ($redirect && $redirect_middleware) {
|
||||
$middlewares = $middlewares . ',' . $redirect_middleware;
|
||||
}
|
||||
$labels->push("traefik.http.routers.{$http_label}.middlewares={$middlewares}");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user