mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
fix: prevent to have empty traefik config in order to prevent domain crashes #38
This commit is contained in:
@@ -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;
|
||||
}),
|
||||
|
||||
@@ -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`,
|
||||
|
||||
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user