From 5aaa1e55f9ea7088592fc97cd17879a1f34b888f Mon Sep 17 00:00:00 2001 From: Lorenzo Migliorero Date: Wed, 31 Jul 2024 09:58:57 +0200 Subject: [PATCH] fix: cert condition --- .../server/update-server-config.test.ts | 18 ++++++++++++++++++ .../dokploy/server/utils/traefik/web-server.ts | 8 ++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/apps/dokploy/__test__/traefik/server/update-server-config.test.ts b/apps/dokploy/__test__/traefik/server/update-server-config.test.ts index 662c1ad7..1e853aa4 100644 --- a/apps/dokploy/__test__/traefik/server/update-server-config.test.ts +++ b/apps/dokploy/__test__/traefik/server/update-server-config.test.ts @@ -77,3 +77,21 @@ test("Should not touch config without host", () => { expect(originalConfig).toEqual(config); }); + +test("Should remove web-secure if https rollback to http", () => { + const originalConfig: FileConfig = loadOrCreateConfig("dokploy"); + + updateServerTraefik( + { ...baseAdmin, certificateType: "letsencrypt" }, + "example.com", + ); + + updateServerTraefik({ ...baseAdmin, certificateType: "none" }, "example.com"); + + const config: FileConfig = loadOrCreateConfig("dokploy"); + + expect(config.http?.routers?.["dokploy-router-app-secure"]).toBeUndefined(); + expect( + config.http?.routers?.["dokploy-router-app"]?.middlewares, + ).not.toContain("redirect-to-https"); +}); diff --git a/apps/dokploy/server/utils/traefik/web-server.ts b/apps/dokploy/server/utils/traefik/web-server.ts index fc2a1fc0..63e10c2a 100644 --- a/apps/dokploy/server/utils/traefik/web-server.ts +++ b/apps/dokploy/server/utils/traefik/web-server.ts @@ -26,13 +26,13 @@ export const updateServerTraefik = ( config.http.routers[`${appName}-router-app-secure`] = { ...currentRouterConfig, entryPoints: ["web-secure"], - tls: - admin?.certificateType === "letsencrypt" - ? { certResolver: "letsencrypt" } - : undefined, + tls: { certResolver: "letsencrypt" }, }; currentRouterConfig.middlewares = ["redirect-to-https"]; + } else { + delete config.http.routers[`${appName}-router-app-secure`]; + currentRouterConfig.middlewares = []; } }