Skip to content

Commit

Permalink
fix(compose): add path prefix inside Host rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Siumauricio committed Nov 12, 2024
1 parent e0fe4e4 commit 58b185f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
9 changes: 4 additions & 5 deletions apps/dokploy/__test__/compose/domain/labels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ describe("createDomainLabels", () => {
"traefik.http.routers.test-app-1-web.entrypoints=web",
"traefik.http.services.test-app-1-web.loadbalancer.server.port=8080",
"traefik.http.routers.test-app-1-web.service=test-app-1-web",
"traefik.http.routers.test-app-1-web.rule=PathPrefix(`/`)",
]);
});

Expand All @@ -37,21 +36,21 @@ describe("createDomainLabels", () => {
"traefik.http.routers.test-app-1-websecure.entrypoints=websecure",
"traefik.http.services.test-app-1-websecure.loadbalancer.server.port=8080",
"traefik.http.routers.test-app-1-websecure.service=test-app-1-websecure",
"traefik.http.routers.test-app-1-websecure.rule=PathPrefix(`/`)",
]);
});

it("shouldn't add the path prefix if is empty", async () => {
it("should add the path prefix if is different than / empty", async () => {
const labels = await createDomainLabels(
appName,
{
...baseDomain,
path: "",
path: "/hello",
},
"websecure",
);

expect(labels).toEqual([
"traefik.http.routers.test-app-1-websecure.rule=Host(`example.com`)",
"traefik.http.routers.test-app-1-websecure.rule=Host(`example.com`) && PathPrefix(`/hello`)",
"traefik.http.routers.test-app-1-websecure.entrypoints=websecure",
"traefik.http.services.test-app-1-websecure.loadbalancer.server.port=8080",
"traefik.http.routers.test-app-1-websecure.service=test-app-1-websecure",
Expand Down
10 changes: 2 additions & 8 deletions packages/server/src/utils/docker/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,21 +259,15 @@ export const createDomainLabels = async (
domain: Domain,
entrypoint: "web" | "websecure",
) => {
const { host, port, https, uniqueConfigKey, certificateType } = domain;
const { host, port, https, uniqueConfigKey, certificateType, path } = domain;
const routerName = `${appName}-${uniqueConfigKey}-${entrypoint}`;
const labels = [
`traefik.http.routers.${routerName}.rule=Host(\`${host}\`)`,
`traefik.http.routers.${routerName}.rule=Host(\`${host}\`)${path && path !== "/" ? ` && PathPrefix(\`${path}\`)` : ""}`,
`traefik.http.routers.${routerName}.entrypoints=${entrypoint}`,
`traefik.http.services.${routerName}.loadbalancer.server.port=${port}`,
`traefik.http.routers.${routerName}.service=${routerName}`,
];

if (domain.path) {
labels.push(
`traefik.http.routers.${routerName}.rule=PathPrefix(\`${domain.path}\`)`,
);
}

if (entrypoint === "web" && https) {
labels.push(
`traefik.http.routers.${routerName}.middlewares=redirect-to-https@file`,
Expand Down

0 comments on commit 58b185f

Please sign in to comment.