refactor(traefik): improve config removal logic and error handling

- Consolidated command execution for removing Traefik config files by using a single command string.
- Enhanced error handling to log issues encountered during the removal process for both local and remote configurations.
This commit is contained in:
Mauricio Siu
2026-03-30 08:05:47 -06:00
parent 290a03ccfb
commit 8053ee7724
@@ -5,7 +5,7 @@ import { paths } from "@dokploy/server/constants";
import type { Domain } from "@dokploy/server/services/domain"; import type { Domain } from "@dokploy/server/services/domain";
import { parse, stringify } from "yaml"; import { parse, stringify } from "yaml";
import { encodeBase64 } from "../docker/utils"; import { encodeBase64 } from "../docker/utils";
import { execAsyncRemote } from "../process/execAsync"; import { execAsync, execAsyncRemote } from "../process/execAsync";
import type { FileConfig, HttpLoadBalancerService } from "./file-types"; import type { FileConfig, HttpLoadBalancerService } from "./file-types";
export const createTraefikConfig = (appName: string) => { export const createTraefikConfig = (appName: string) => {
@@ -57,18 +57,16 @@ export const removeTraefikConfig = async (
try { try {
const { DYNAMIC_TRAEFIK_PATH } = paths(!!serverId); const { DYNAMIC_TRAEFIK_PATH } = paths(!!serverId);
const configPath = path.join(DYNAMIC_TRAEFIK_PATH, `${appName}.yml`); const configPath = path.join(DYNAMIC_TRAEFIK_PATH, `${appName}.yml`);
const command = `rm -f ${configPath}`;
if (serverId) { if (serverId) {
await execAsyncRemote(serverId, `rm ${configPath}`); await execAsyncRemote(serverId, command);
} else { } else {
if (fs.existsSync(configPath)) { await execAsync(command);
await fs.promises.unlink(configPath);
}
} }
if (fs.existsSync(configPath)) { } catch (error) {
await fs.promises.unlink(configPath); console.error(`Error removing traefik config for ${appName}:`, error);
} }
} catch {}
}; };
export const removeTraefikConfigRemote = async ( export const removeTraefikConfigRemote = async (
@@ -78,8 +76,13 @@ export const removeTraefikConfigRemote = async (
try { try {
const { DYNAMIC_TRAEFIK_PATH } = paths(true); const { DYNAMIC_TRAEFIK_PATH } = paths(true);
const configPath = path.join(DYNAMIC_TRAEFIK_PATH, `${appName}.yml`); const configPath = path.join(DYNAMIC_TRAEFIK_PATH, `${appName}.yml`);
await execAsyncRemote(serverId, `rm ${configPath}`); await execAsyncRemote(serverId, `rm -f ${configPath}`);
} catch {} } catch (error) {
console.error(
`Error removing remote traefik config for ${appName}:`,
error,
);
}
}; };
export const loadOrCreateConfig = (appName: string): FileConfig => { export const loadOrCreateConfig = (appName: string): FileConfig => {