fix maintenance router name

This commit is contained in:
Pallavi Kumari
2025-11-02 20:50:13 +05:30
committed by Owen Schwartz
parent 188994ce84
commit 096a2bfa10
2 changed files with 11 additions and 13 deletions

View File

@@ -385,7 +385,7 @@ export async function getTraefikConfig(
if (resource.maintenanceModeEnabled) { if (resource.maintenanceModeEnabled) {
if (resource.maintenanceModeType === "forced") { if (resource.maintenanceModeType === "forced") {
showMaintenancePage = true; showMaintenancePage = true;
logger.info( logger.debug(
`Resource ${resource.name} (${fullDomain}) is in FORCED maintenance mode` `Resource ${resource.name} (${fullDomain}) is in FORCED maintenance mode`
); );
} else if (resource.maintenanceModeType === "automatic") { } else if (resource.maintenanceModeType === "automatic") {
@@ -400,7 +400,7 @@ export async function getTraefikConfig(
if (showMaintenancePage) { if (showMaintenancePage) {
const maintenanceServiceName = `${key}-maintenance-service`; const maintenanceServiceName = `${key}-maintenance-service`;
const routerName = `${key}-maintenance-router`; const maintenanceRouterName = `${key}-maintenance-router`;
const maintenancePort = config.getRawConfig().traefik.maintenance_port || 8888; const maintenancePort = config.getRawConfig().traefik.maintenance_port || 8888;
const entrypointHttp = config.getRawConfig().traefik.http_entrypoint; const entrypointHttp = config.getRawConfig().traefik.http_entrypoint;
@@ -415,7 +415,7 @@ export async function getTraefikConfig(
const tls = { const tls = {
certResolver: resource.domainCertResolver?.trim() || certResolver: resource.domainCertResolver?.trim() ||
config.getRawConfig().traefik.cert_resolver, config.getRawConfig().traefik.cert_resolver,
...(resource.preferWildcardCert ?? config.getRawConfig().traefik.prefer_wildcard_cert ...(config.getRawConfig().traefik.prefer_wildcard_cert
? { domains: [{ main: wildCard }] } ? { domains: [{ main: wildCard }] }
: {}) : {})
}; };
@@ -431,7 +431,7 @@ export async function getTraefikConfig(
const rule = `Host(\`${fullDomain}\`)`; const rule = `Host(\`${fullDomain}\`)`;
config_output.http.routers[routerName] = { config_output.http.routers[maintenanceRouterName] = {
entryPoints: [resource.ssl ? entrypointHttps : entrypointHttp], entryPoints: [resource.ssl ? entrypointHttps : entrypointHttp],
service: maintenanceServiceName, service: maintenanceServiceName,
rule, rule,
@@ -440,7 +440,7 @@ export async function getTraefikConfig(
}; };
if (resource.ssl) { if (resource.ssl) {
config_output.http.routers[`${routerName}-redirect`] = { config_output.http.routers[`${maintenanceRouterName}-redirect`] = {
entryPoints: [entrypointHttp], entryPoints: [entrypointHttp],
middlewares: [redirectHttpsMiddlewareName], middlewares: [redirectHttpsMiddlewareName],
service: maintenanceServiceName, service: maintenanceServiceName,
@@ -451,7 +451,6 @@ export async function getTraefikConfig(
continue; continue;
} }
const domainParts = fullDomain.split("."); const domainParts = fullDomain.split(".");
let wildCard; let wildCard;
if (domainParts.length <= 2) { if (domainParts.length <= 2) {

View File

@@ -8,14 +8,12 @@ import path from 'path';
import fs from 'fs'; import fs from 'fs';
const MAINTENANCE_DIR = path.join(process.cwd(), 'maintenance-pages'); const MAINTENANCE_DIR = path.join(process.cwd(), 'maintenance-pages');
if (!fs.existsSync(MAINTENANCE_DIR)) { if (!fs.existsSync(MAINTENANCE_DIR)) {
fs.mkdirSync(MAINTENANCE_DIR, { recursive: true }); fs.mkdirSync(MAINTENANCE_DIR, { recursive: true });
} }
export async function generateMaintenanceFiles() { export async function generateMaintenanceFiles() {
logger.info('Regenerating maintenance page files'); logger.info('Regenerating maintenance page files');
const maintenanceResources = await db const maintenanceResources = await db
.select() .select()
.from(resources) .from(resources)
@@ -38,7 +36,7 @@ export async function generateMaintenanceFiles() {
resource.maintenanceEstimatedTime resource.maintenanceEstimatedTime
); );
const filename = `maintenance-${resource.fullDomain}.html`; const filename = `maintenance-${resource.fullDomain.replace(/\./g, '_')}.html`;
const filepath = path.join(MAINTENANCE_DIR, filename); const filepath = path.join(MAINTENANCE_DIR, filename);
fs.writeFileSync(filepath, html, 'utf-8'); fs.writeFileSync(filepath, html, 'utf-8');
@@ -66,7 +64,8 @@ export function startMaintenanceServer() {
return res.status(400).send("Missing Host header"); return res.status(400).send("Missing Host header");
} }
const maintenanceFile = path.join(MAINTENANCE_DIR, `maintenance-${host}.html`); const hostname = host.split(':')[0];
const maintenanceFile = path.join(MAINTENANCE_DIR, `maintenance-${hostname}.html`);
if (fs.existsSync(maintenanceFile)) { if (fs.existsSync(maintenanceFile)) {
res.status(503) res.status(503)
@@ -78,7 +77,7 @@ export function startMaintenanceServer() {
const [resource] = await db const [resource] = await db
.select() .select()
.from(resources) .from(resources)
.where(eq(resources.fullDomain, host)); .where(eq(resources.fullDomain, hostname));
if (resource?.maintenanceModeEnabled) { if (resource?.maintenanceModeEnabled) {
const html = generateMaintenanceHTML( const html = generateMaintenanceHTML(