mirror of
https://github.com/fosrl/pangolin.git
synced 2026-01-28 22:00:51 +00:00
fix maintenance router name
This commit is contained in:
committed by
Owen Schwartz
parent
188994ce84
commit
096a2bfa10
@@ -385,7 +385,7 @@ export async function getTraefikConfig(
|
||||
if (resource.maintenanceModeEnabled) {
|
||||
if (resource.maintenanceModeType === "forced") {
|
||||
showMaintenancePage = true;
|
||||
logger.info(
|
||||
logger.debug(
|
||||
`Resource ${resource.name} (${fullDomain}) is in FORCED maintenance mode`
|
||||
);
|
||||
} else if (resource.maintenanceModeType === "automatic") {
|
||||
@@ -400,7 +400,7 @@ export async function getTraefikConfig(
|
||||
|
||||
if (showMaintenancePage) {
|
||||
const maintenanceServiceName = `${key}-maintenance-service`;
|
||||
const routerName = `${key}-maintenance-router`;
|
||||
const maintenanceRouterName = `${key}-maintenance-router`;
|
||||
|
||||
const maintenancePort = config.getRawConfig().traefik.maintenance_port || 8888;
|
||||
const entrypointHttp = config.getRawConfig().traefik.http_entrypoint;
|
||||
@@ -415,7 +415,7 @@ export async function getTraefikConfig(
|
||||
const tls = {
|
||||
certResolver: resource.domainCertResolver?.trim() ||
|
||||
config.getRawConfig().traefik.cert_resolver,
|
||||
...(resource.preferWildcardCert ?? config.getRawConfig().traefik.prefer_wildcard_cert
|
||||
...(config.getRawConfig().traefik.prefer_wildcard_cert
|
||||
? { domains: [{ main: wildCard }] }
|
||||
: {})
|
||||
};
|
||||
@@ -431,7 +431,7 @@ export async function getTraefikConfig(
|
||||
|
||||
const rule = `Host(\`${fullDomain}\`)`;
|
||||
|
||||
config_output.http.routers[routerName] = {
|
||||
config_output.http.routers[maintenanceRouterName] = {
|
||||
entryPoints: [resource.ssl ? entrypointHttps : entrypointHttp],
|
||||
service: maintenanceServiceName,
|
||||
rule,
|
||||
@@ -440,7 +440,7 @@ export async function getTraefikConfig(
|
||||
};
|
||||
|
||||
if (resource.ssl) {
|
||||
config_output.http.routers[`${routerName}-redirect`] = {
|
||||
config_output.http.routers[`${maintenanceRouterName}-redirect`] = {
|
||||
entryPoints: [entrypointHttp],
|
||||
middlewares: [redirectHttpsMiddlewareName],
|
||||
service: maintenanceServiceName,
|
||||
@@ -451,7 +451,6 @@ export async function getTraefikConfig(
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
const domainParts = fullDomain.split(".");
|
||||
let wildCard;
|
||||
if (domainParts.length <= 2) {
|
||||
|
||||
@@ -8,14 +8,12 @@ import path from 'path';
|
||||
import fs from 'fs';
|
||||
|
||||
const MAINTENANCE_DIR = path.join(process.cwd(), 'maintenance-pages');
|
||||
|
||||
if (!fs.existsSync(MAINTENANCE_DIR)) {
|
||||
fs.mkdirSync(MAINTENANCE_DIR, { recursive: true });
|
||||
}
|
||||
|
||||
export async function generateMaintenanceFiles() {
|
||||
logger.info('Regenerating maintenance page files');
|
||||
|
||||
const maintenanceResources = await db
|
||||
.select()
|
||||
.from(resources)
|
||||
@@ -38,7 +36,7 @@ export async function generateMaintenanceFiles() {
|
||||
resource.maintenanceEstimatedTime
|
||||
);
|
||||
|
||||
const filename = `maintenance-${resource.fullDomain}.html`;
|
||||
const filename = `maintenance-${resource.fullDomain.replace(/\./g, '_')}.html`;
|
||||
const filepath = path.join(MAINTENANCE_DIR, filename);
|
||||
|
||||
fs.writeFileSync(filepath, html, 'utf-8');
|
||||
@@ -58,7 +56,7 @@ export function startMaintenanceServer() {
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
|
||||
app.use(async (req, res) => {
|
||||
const host = req.headers.host;
|
||||
|
||||
@@ -66,7 +64,8 @@ export function startMaintenanceServer() {
|
||||
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)) {
|
||||
res.status(503)
|
||||
@@ -78,7 +77,7 @@ export function startMaintenanceServer() {
|
||||
const [resource] = await db
|
||||
.select()
|
||||
.from(resources)
|
||||
.where(eq(resources.fullDomain, host));
|
||||
.where(eq(resources.fullDomain, hostname));
|
||||
|
||||
if (resource?.maintenanceModeEnabled) {
|
||||
const html = generateMaintenanceHTML(
|
||||
@@ -99,7 +98,7 @@ export function startMaintenanceServer() {
|
||||
res.status(404).send('Not found');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
const port = config.getRawConfig().traefik?.maintenance_port || 8888;
|
||||
|
||||
app.listen(port, '0.0.0.0', () => {
|
||||
|
||||
Reference in New Issue
Block a user