Trying to get this to work

This commit is contained in:
Owen 2025-02-06 21:15:51 -05:00
parent fd806f5061
commit 7e457c548e
No known key found for this signature in database
GPG key ID: 8271FDFFD9E0CCBD

View file

@ -59,6 +59,8 @@ export async function traefikConfigProvider(
) )
.groupBy(resources.resourceId); .groupBy(resources.resourceId);
logger.debug(JSON.stringify(allResources, null, 2));
if (!allResources.length) { if (!allResources.length) {
return res.status(HttpCode.OK).json({}); return res.status(HttpCode.OK).json({});
} }
@ -149,7 +151,9 @@ export async function traefikConfigProvider(
: {}) : {})
}; };
logger.debug(config.getRawConfig().traefik.prefer_wildcard_cert) logger.debug(
config.getRawConfig().traefik.prefer_wildcard_cert
);
const additionalMiddlewares = const additionalMiddlewares =
config.getRawConfig().traefik.additional_middlewares || []; config.getRawConfig().traefik.additional_middlewares || [];
@ -176,7 +180,7 @@ export async function traefikConfigProvider(
], ],
middlewares: [redirectHttpsMiddlewareName], middlewares: [redirectHttpsMiddlewareName],
service: serviceName, service: serviceName,
rule: convertUrlToTraefikRegex(fullDomain), rule: convertUrlToTraefikRegex(fullDomain)
}; };
} }
@ -298,18 +302,18 @@ export async function traefikConfigProvider(
function convertUrlToTraefikRegex(url: string): string { function convertUrlToTraefikRegex(url: string): string {
// Check if the URL contains a wildcard // Check if the URL contains a wildcard
if (!url.includes('*')) { if (!url.includes("*")) {
return `Host(\`${url}\`)`; return `Host(\`${url}\`)`;
} }
// Escape dots and replace wildcard with regex pattern // Escape dots and replace wildcard with regex pattern
// Handle the case where * already has dots around it // Handle the case where * already has dots around it
const regexPattern = url const regexPattern = url
.replace(/\./g, '\\.') // First escape all dots .replace(/\./g, "\\.") // First escape all dots
.replace(/\\\.\*\\\./g, '.+\\.') // Replace \.*.\ with .+\. .replace(/\\\.\*\\\./g, ".+\\.") // Replace \.*.\ with .+\.
.replace(/\*\\\./g, '.+\\.') // Replace *.\ with .+\. .replace(/\*\\\./g, ".+\\.") // Replace *.\ with .+\.
.replace(/\\\.\*/g, '\\.+') // Replace \.* with \.+ .replace(/\\\.\*/g, "\\.+") // Replace \.* with \.+
.replace(/\*/g, '.+'); // Replace any remaining * with .+ .replace(/\*/g, ".+"); // Replace any remaining * with .+
return `HostRegexp(\`^${regexPattern}$\`)`; return `HostRegexp(\`^${regexPattern}$\`)`;
} }