feat(domains): add internal path routing and

strip path functionality to compose

  - Add internalPath field to route requests
  to different paths internally
  - Add stripPath option to remove external
  path prefix before forwarding
  - Improves validation for stripPath (requires
  non-root path) and internalPath (must start
  with /)
This commit is contained in:
Jhonatan Caldeira
2025-06-22 14:55:27 -03:00
parent df8f1252a0
commit fd0f679d0f
3 changed files with 80 additions and 0 deletions

View File

@@ -301,6 +301,8 @@ export const createDomainLabels = (
certificateType,
path,
customCertResolver,
stripPath,
internalPath
} = domain;
const routerName = `${appName}-${uniqueConfigKey}-${entrypoint}`;
const labels = [
@@ -310,6 +312,26 @@ export const createDomainLabels = (
`traefik.http.routers.${routerName}.service=${routerName}`,
];
// Validate stripPath - it should only be used when path is defined and not "/"
if (stripPath) {
if (!path || path === "/") {
console.warn(`stripPath is enabled but path is not defined or is "/" for domain ${host}`);
} else {
const middlewareName = `stripprefix-${appName}-${uniqueConfigKey}`;
labels.push(`traefik.http.middlewares.${middlewareName}.stripprefix.prefixes=${path}`);
}
}
// Validate internalPath - ensure it's a valid path format
if (internalPath && internalPath !== "/") {
if (!internalPath.startsWith("/")) {
console.warn(`internalPath "${internalPath}" should start with "/" and not be empty for domain ${host}`);
} else {
const middlewareName = `addprefix-${appName}-${uniqueConfigKey}`;
labels.push(`traefik.http.middlewares.${middlewareName}.addprefix.prefix=${internalPath}`);
}
}
if (entrypoint === "web" && https) {
labels.push(
`traefik.http.routers.${routerName}.middlewares=redirect-to-https@file`,