mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-03 17:26:38 +00:00
Update traefik dynamic config to also use resource name
This commit is contained in:
@@ -54,6 +54,7 @@ export async function getTraefikConfig(
|
|||||||
.select({
|
.select({
|
||||||
// Resource fields
|
// Resource fields
|
||||||
resourceId: resources.resourceId,
|
resourceId: resources.resourceId,
|
||||||
|
resourceName: resources.name,
|
||||||
fullDomain: resources.fullDomain,
|
fullDomain: resources.fullDomain,
|
||||||
ssl: resources.ssl,
|
ssl: resources.ssl,
|
||||||
http: resources.http,
|
http: resources.http,
|
||||||
@@ -127,7 +128,8 @@ export async function getTraefikConfig(
|
|||||||
|
|
||||||
resourcesWithTargetsAndSites.forEach((row) => {
|
resourcesWithTargetsAndSites.forEach((row) => {
|
||||||
const resourceId = row.resourceId;
|
const resourceId = row.resourceId;
|
||||||
const targetPath = sanitizePath(row.path) || ""; // Handle null/undefined paths
|
const resourceName = sanitize(row.resourceName) || "";
|
||||||
|
const targetPath = sanitize(row.path) || ""; // Handle null/undefined paths
|
||||||
const pathMatchType = row.pathMatchType || "";
|
const pathMatchType = row.pathMatchType || "";
|
||||||
const priority = row.priority ?? 100;
|
const priority = row.priority ?? 100;
|
||||||
|
|
||||||
@@ -142,6 +144,7 @@ export async function getTraefikConfig(
|
|||||||
if (!resourcesMap.has(mapKey)) {
|
if (!resourcesMap.has(mapKey)) {
|
||||||
resourcesMap.set(mapKey, {
|
resourcesMap.set(mapKey, {
|
||||||
resourceId: row.resourceId,
|
resourceId: row.resourceId,
|
||||||
|
name: resourceName,
|
||||||
fullDomain: row.fullDomain,
|
fullDomain: row.fullDomain,
|
||||||
ssl: row.ssl,
|
ssl: row.ssl,
|
||||||
http: row.http,
|
http: row.http,
|
||||||
@@ -211,8 +214,8 @@ export async function getTraefikConfig(
|
|||||||
for (const [key, resource] of resourcesMap.entries()) {
|
for (const [key, resource] of resourcesMap.entries()) {
|
||||||
const targets = resource.targets;
|
const targets = resource.targets;
|
||||||
|
|
||||||
const routerName = `${key}-router`;
|
const routerName = `${key}-${resource.name}-router`;
|
||||||
const serviceName = `${key}-service`;
|
const serviceName = `${key}-${resource.name}-service`;
|
||||||
const fullDomain = `${resource.fullDomain}`;
|
const fullDomain = `${resource.fullDomain}`;
|
||||||
const transportName = `${key}-transport`;
|
const transportName = `${key}-transport`;
|
||||||
const headersMiddlewareName = `${key}-headers-middleware`;
|
const headersMiddlewareName = `${key}-headers-middleware`;
|
||||||
@@ -707,12 +710,12 @@ export async function getTraefikConfig(
|
|||||||
return config_output;
|
return config_output;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sanitizePath(path: string | null | undefined): string | undefined {
|
function sanitize(input: string | null | undefined): string | undefined {
|
||||||
if (!path) return undefined;
|
if (!input) return undefined;
|
||||||
// clean any non alphanumeric characters from the path and replace with dashes
|
// clean any non alphanumeric characters from the input and replace with dashes
|
||||||
// the path cant be too long either, so limit to 50 characters
|
// the input cant be too long either, so limit to 50 characters
|
||||||
if (path.length > 50) {
|
if (input.length > 50) {
|
||||||
path = path.substring(0, 50);
|
input = input.substring(0, 50);
|
||||||
}
|
}
|
||||||
return path.replace(/[^a-zA-Z0-9]/g, "");
|
return input.replace(/[^a-zA-Z0-9]/g, "");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user