Skip to content

Commit d9f8512

Browse files
committed
Update traefik dynamic config to also use resource name
1 parent 1f9f3fd commit d9f8512

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

server/routers/traefik/getTraefikConfig.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export async function getTraefikConfig(
111111
.select({
112112
// Resource fields
113113
resourceId: resources.resourceId,
114+
resourceName: resources.name,
114115
fullDomain: resources.fullDomain,
115116
ssl: resources.ssl,
116117
http: resources.http,
@@ -161,7 +162,8 @@ export async function getTraefikConfig(
161162

162163
resourcesWithTargetsAndSites.forEach((row) => {
163164
const resourceId = row.resourceId;
164-
const targetPath = sanitizePath(row.path) || ""; // Handle null/undefined paths
165+
const resourceName = sanitize(row.resourceName) || "";
166+
const targetPath = sanitize(row.path) || ""; // Handle null/undefined paths
165167
const pathMatchType = row.pathMatchType || "";
166168

167169
// Create a unique key combining resourceId and path+pathMatchType
@@ -171,6 +173,7 @@ export async function getTraefikConfig(
171173
if (!resourcesMap.has(mapKey)) {
172174
resourcesMap.set(mapKey, {
173175
resourceId: row.resourceId,
176+
name: resourceName,
174177
fullDomain: row.fullDomain,
175178
ssl: row.ssl,
176179
http: row.http,
@@ -230,8 +233,8 @@ export async function getTraefikConfig(
230233
for (const [key, resource] of resourcesMap.entries()) {
231234
const targets = resource.targets;
232235

233-
const routerName = `${key}-router`;
234-
const serviceName = `${key}-service`;
236+
const routerName = `${key}-${resource.name}-router`;
237+
const serviceName = `${key}-${resource.name}-service`;
235238
const fullDomain = `${resource.fullDomain}`;
236239
const transportName = `${key}-transport`;
237240
const headersMiddlewareName = `${key}-headers-middleware`;
@@ -583,12 +586,12 @@ export async function getTraefikConfig(
583586
return config_output;
584587
}
585588

586-
function sanitizePath(path: string | null | undefined): string | undefined {
587-
if (!path) return undefined;
588-
// clean any non alphanumeric characters from the path and replace with dashes
589-
// the path cant be too long either, so limit to 50 characters
590-
if (path.length > 50) {
591-
path = path.substring(0, 50);
589+
function sanitize(input: string | null | undefined): string | undefined {
590+
if (!input) return undefined;
591+
// clean any non alphanumeric characters from the input and replace with dashes
592+
// the input cant be too long either, so limit to 50 characters
593+
if (input.length > 50) {
594+
input = input.substring(0, 50);
592595
}
593-
return path.replace(/[^a-zA-Z0-9]/g, "");
596+
return input.replace(/[^a-zA-Z0-9]/g, "");
594597
}

0 commit comments

Comments
 (0)