Skip to content

Commit 832a987

Browse files
authored
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…
2 parents 6613cb7 + 65b3ce8 commit 832a987

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

packages/server/src/templates/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,16 @@ export const generateRandomDomain = ({
3737
const hash = randomBytes(3).toString("hex");
3838
const slugIp = serverIp.replaceAll(".", "-").replaceAll(":", "-");
3939

40-
return `${projectName}-${hash}${slugIp === "" ? "" : `-${slugIp}`}.traefik.me`;
40+
// Domain labels have a max length of 63 characters
41+
// Reserve space for: hash (6) + separators (1-2) + ip section + dot + traefik.me (10)
42+
// Approx: 6 + 2 + (variable ip length) + 11 = ~19-30 chars for other parts
43+
const maxProjectNameLength = 40;
44+
const truncatedProjectName =
45+
projectName.length > maxProjectNameLength
46+
? projectName.substring(0, maxProjectNameLength)
47+
: projectName;
48+
49+
return `${truncatedProjectName}-${hash}${slugIp === "" ? "" : `-${slugIp}`}.traefik.me`;
4150
};
4251

4352
export const generateHash = (length = 8): string => {

0 commit comments

Comments
 (0)