mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-04 19:22:16 +00:00
fix: swap stripPrefix and addPrefix middleware order in Traefik domain config
When both stripPath and internalPath are configured, addPrefix was pushed before stripPrefix causing incorrect path rewriting (e.g. /app/v2/public/api instead of /app/v2/api). Traefik executes middlewares in array order, so stripPrefix must come first. Closes #4061
This commit is contained in:
@@ -424,6 +424,26 @@ test("Custom entrypoint with internalPath adds addprefix middleware", async () =
|
|||||||
expect(router.entryPoints).toEqual(["custom"]);
|
expect(router.entryPoints).toEqual(["custom"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("stripPath and internalPath together: stripprefix must come before addprefix", async () => {
|
||||||
|
const router = await createRouterConfig(
|
||||||
|
baseApp,
|
||||||
|
{
|
||||||
|
...baseDomain,
|
||||||
|
path: "/public",
|
||||||
|
stripPath: true,
|
||||||
|
internalPath: "/app/v2",
|
||||||
|
},
|
||||||
|
"web",
|
||||||
|
);
|
||||||
|
|
||||||
|
const stripIndex = router.middlewares?.indexOf("stripprefix--1") ?? -1;
|
||||||
|
const addIndex = router.middlewares?.indexOf("addprefix--1") ?? -1;
|
||||||
|
|
||||||
|
expect(stripIndex).toBeGreaterThanOrEqual(0);
|
||||||
|
expect(addIndex).toBeGreaterThanOrEqual(0);
|
||||||
|
expect(stripIndex).toBeLessThan(addIndex);
|
||||||
|
});
|
||||||
|
|
||||||
test("Custom entrypoint with https and custom cert resolver", async () => {
|
test("Custom entrypoint with https and custom cert resolver", async () => {
|
||||||
const router = await createRouterConfig(
|
const router = await createRouterConfig(
|
||||||
baseApp,
|
baseApp,
|
||||||
|
|||||||
@@ -151,16 +151,18 @@ export const createRouterConfig = async (
|
|||||||
routerConfig.middlewares?.push("redirect-to-https");
|
routerConfig.middlewares?.push("redirect-to-https");
|
||||||
} else {
|
} else {
|
||||||
// Add path rewriting middleware if needed
|
// Add path rewriting middleware if needed
|
||||||
if (internalPath && internalPath !== "/" && internalPath !== path) {
|
// stripPrefix must come before addPrefix so Traefik strips the
|
||||||
const pathMiddleware = `addprefix-${appName}-${uniqueConfigKey}`;
|
// public path first, then prepends the internal path.
|
||||||
routerConfig.middlewares?.push(pathMiddleware);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stripPath && path && path !== "/") {
|
if (stripPath && path && path !== "/") {
|
||||||
const stripMiddleware = `stripprefix-${appName}-${uniqueConfigKey}`;
|
const stripMiddleware = `stripprefix-${appName}-${uniqueConfigKey}`;
|
||||||
routerConfig.middlewares?.push(stripMiddleware);
|
routerConfig.middlewares?.push(stripMiddleware);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (internalPath && internalPath !== "/" && internalPath !== path) {
|
||||||
|
const pathMiddleware = `addprefix-${appName}-${uniqueConfigKey}`;
|
||||||
|
routerConfig.middlewares?.push(pathMiddleware);
|
||||||
|
}
|
||||||
|
|
||||||
// redirects - skip for preview deployments as wildcard subdomains
|
// redirects - skip for preview deployments as wildcard subdomains
|
||||||
// should not inherit parent redirect rules (e.g., www-redirect)
|
// should not inherit parent redirect rules (e.g., www-redirect)
|
||||||
if (domain.domainType !== "preview") {
|
if (domain.domainType !== "preview") {
|
||||||
|
|||||||
Reference in New Issue
Block a user