Merge pull request #2943 from Dokploy/2905-subdomain-length-of-random-traefik-domain-isnt-checked-and-exceeds-maximum

feat(domain): truncate project name to comply with domain label lengt…
This commit is contained in:
Mauricio Siu
2025-11-02 17:21:41 -06:00
committed by GitHub

View File

@@ -37,7 +37,16 @@ export const generateRandomDomain = ({
const hash = randomBytes(3).toString("hex");
const slugIp = serverIp.replaceAll(".", "-").replaceAll(":", "-");
return `${projectName}-${hash}${slugIp === "" ? "" : `-${slugIp}`}.traefik.me`;
// Domain labels have a max length of 63 characters
// Reserve space for: hash (6) + separators (1-2) + ip section + dot + traefik.me (10)
// Approx: 6 + 2 + (variable ip length) + 11 = ~19-30 chars for other parts
const maxProjectNameLength = 40;
const truncatedProjectName =
projectName.length > maxProjectNameLength
? projectName.substring(0, maxProjectNameLength)
: projectName;
return `${truncatedProjectName}-${hash}${slugIp === "" ? "" : `-${slugIp}`}.traefik.me`;
};
export const generateHash = (length = 8): string => {