Skip to content

Commit 8053ee7

Browse files
committed
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.
1 parent 290a03c commit 8053ee7

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

packages/server/src/utils/traefik/application.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { paths } from "@dokploy/server/constants";
55
import type { Domain } from "@dokploy/server/services/domain";
66
import { parse, stringify } from "yaml";
77
import { encodeBase64 } from "../docker/utils";
8-
import { execAsyncRemote } from "../process/execAsync";
8+
import { execAsync, execAsyncRemote } from "../process/execAsync";
99
import type { FileConfig, HttpLoadBalancerService } from "./file-types";
1010

1111
export const createTraefikConfig = (appName: string) => {
@@ -57,18 +57,16 @@ export const removeTraefikConfig = async (
5757
try {
5858
const { DYNAMIC_TRAEFIK_PATH } = paths(!!serverId);
5959
const configPath = path.join(DYNAMIC_TRAEFIK_PATH, `${appName}.yml`);
60+
const command = `rm -f ${configPath}`;
6061

6162
if (serverId) {
62-
await execAsyncRemote(serverId, `rm ${configPath}`);
63+
await execAsyncRemote(serverId, command);
6364
} else {
64-
if (fs.existsSync(configPath)) {
65-
await fs.promises.unlink(configPath);
66-
}
67-
}
68-
if (fs.existsSync(configPath)) {
69-
await fs.promises.unlink(configPath);
65+
await execAsync(command);
7066
}
71-
} catch {}
67+
} catch (error) {
68+
console.error(`Error removing traefik config for ${appName}:`, error);
69+
}
7270
};
7371

7472
export const removeTraefikConfigRemote = async (
@@ -78,8 +76,13 @@ export const removeTraefikConfigRemote = async (
7876
try {
7977
const { DYNAMIC_TRAEFIK_PATH } = paths(true);
8078
const configPath = path.join(DYNAMIC_TRAEFIK_PATH, `${appName}.yml`);
81-
await execAsyncRemote(serverId, `rm ${configPath}`);
82-
} catch {}
79+
await execAsyncRemote(serverId, `rm -f ${configPath}`);
80+
} catch (error) {
81+
console.error(
82+
`Error removing remote traefik config for ${appName}:`,
83+
error,
84+
);
85+
}
8386
};
8487

8588
export const loadOrCreateConfig = (appName: string): FileConfig => {

0 commit comments

Comments
 (0)