diff --git a/server/api/routers/domain.ts b/server/api/routers/domain.ts index 2abe710c3..ace938c01 100644 --- a/server/api/routers/domain.ts +++ b/server/api/routers/domain.ts @@ -52,7 +52,7 @@ export const domainRouter = createTRPCRouter({ .mutation(async ({ input }) => { const domain = await findDomainById(input.domainId); const result = await removeDomainById(input.domainId); - removeDomain(domain.application.appName, domain.uniqueConfigKey); + await removeDomain(domain.application.appName, domain.uniqueConfigKey); return result; }), diff --git a/server/api/services/application.ts b/server/api/services/application.ts index d7efc4339..d5da79c40 100644 --- a/server/api/services/application.ts +++ b/server/api/services/application.ts @@ -36,9 +36,8 @@ export const createApplication = async ( }); } - createTraefikConfig(newApplication.appName); - if (process.env.NODE_ENV === "development") { + createTraefikConfig(newApplication.appName); await tx.insert(domains).values({ applicationId: newApplication.applicationId, host: `${newApplication.appName}.docker.localhost`, diff --git a/server/utils/traefik/domain.ts b/server/utils/traefik/domain.ts index cf0faa17e..689afbbb9 100644 --- a/server/utils/traefik/domain.ts +++ b/server/utils/traefik/domain.ts @@ -1,6 +1,7 @@ import { createServiceConfig, loadOrCreateConfig, + removeTraefikConfig, writeTraefikConfig, } from "./application"; import type { ApplicationNested } from "../builders"; @@ -23,7 +24,7 @@ export const manageDomain = async (app: ApplicationNested, domain: Domain) => { writeTraefikConfig(config, appName); }; -export const removeDomain = (appName: string, uniqueKey: number) => { +export const removeDomain = async (appName: string, uniqueKey: number) => { const config: FileConfig = loadOrCreateConfig(appName); const routerKey = `${appName}-router-${uniqueKey}`; @@ -35,7 +36,15 @@ export const removeDomain = (appName: string, uniqueKey: number) => { delete config.http.services[serviceKey]; } - writeTraefikConfig(config, appName); + // verify if is the last router if so we delete the router + if ( + config?.http?.routers && + Object.keys(config?.http?.routers).length === 0 + ) { + await removeTraefikConfig(appName); + } else { + writeTraefikConfig(config, appName); + } }; export const createRouterConfig = async (