From 797931dfe97e669f5f73c4c132d1c78b85cdbb47 Mon Sep 17 00:00:00 2001 From: Lorenzo Migliorero Date: Mon, 29 Jul 2024 16:31:49 +0200 Subject: [PATCH] feat: remove path prefix if different than / --- __test__/traefik/traefik.test.ts | 11 +++++++++++ server/utils/traefik/domain.ts | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/__test__/traefik/traefik.test.ts b/__test__/traefik/traefik.test.ts index ce35611f..80a10826 100644 --- a/__test__/traefik/traefik.test.ts +++ b/__test__/traefik/traefik.test.ts @@ -88,6 +88,17 @@ test("Web entrypoint on http domain", async () => { ); expect(router.middlewares).not.toContain("redirect-to-https"); + expect(router.rule).not.toContain("PathPrefix"); +}); + +test("Web entrypoint on http domain with custom path", async () => { + const router = await createRouterConfig( + baseApp, + { ...baseDomain, path: "/foo", https: false }, + "web", + ); + + expect(router.rule).toContain("PathPrefix(`/foo`)"); }); test("Web entrypoint on http domain with redirect", async () => { diff --git a/server/utils/traefik/domain.ts b/server/utils/traefik/domain.ts index 401c7a8e..3a34f045 100644 --- a/server/utils/traefik/domain.ts +++ b/server/utils/traefik/domain.ts @@ -77,7 +77,7 @@ export const createRouterConfig = async ( const { host, path, https, uniqueConfigKey } = domain; const routerConfig: HttpRouter = { - rule: `Host(\`${host}\`)${path ? ` && PathPrefix(\`${path}\`)` : ""}`, + rule: `Host(\`${host}\`)${path !== null && path !== "/" ? ` && PathPrefix(\`${path}\`)` : ""}`, service: `${appName}-service-${uniqueConfigKey}`, middlewares: [], entryPoints: [entryPoint],