mirror of
https://github.com/LukeHagar/dokploy.git
synced 2025-12-09 20:37:45 +00:00
refactor: remove unnecessary middleware checks in Traefik config generation
This commit is contained in:
@@ -263,15 +263,6 @@ export const writeTraefikConfigRemote = 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`);
|
||||||
if (traefikConfig.http?.middlewares) {
|
|
||||||
// traefik will fail to start if the file contains middlewares entry but no middlewares are defined
|
|
||||||
const hasNoMiddlewares =
|
|
||||||
Object.keys(traefikConfig.http.middlewares).length === 0;
|
|
||||||
if (hasNoMiddlewares) {
|
|
||||||
// if there aren't any middlewares, remove the whole section
|
|
||||||
delete traefikConfig.http.middlewares;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const yamlStr = stringify(traefikConfig);
|
const yamlStr = stringify(traefikConfig);
|
||||||
await execAsyncRemote(serverId, `echo '${yamlStr}' > ${configPath}`);
|
await execAsyncRemote(serverId, `echo '${yamlStr}' > ${configPath}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -103,14 +103,6 @@ export const loadRemoteMiddlewares = async (serverId: string) => {
|
|||||||
export const writeMiddleware = (config: FileConfig) => {
|
export const writeMiddleware = (config: FileConfig) => {
|
||||||
const { DYNAMIC_TRAEFIK_PATH } = paths();
|
const { DYNAMIC_TRAEFIK_PATH } = paths();
|
||||||
const configPath = join(DYNAMIC_TRAEFIK_PATH, "middlewares.yml");
|
const configPath = join(DYNAMIC_TRAEFIK_PATH, "middlewares.yml");
|
||||||
if (config.http?.middlewares) {
|
|
||||||
// traefik will fail to start if the file contains middlewares entry but no middlewares are defined
|
|
||||||
const hasNoMiddlewares = Object.keys(config.http.middlewares).length === 0;
|
|
||||||
if (hasNoMiddlewares) {
|
|
||||||
// if there aren't any middlewares, remove the whole section
|
|
||||||
delete config.http.middlewares;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const newYamlContent = stringify(config);
|
const newYamlContent = stringify(config);
|
||||||
writeFileSync(configPath, newYamlContent, "utf8");
|
writeFileSync(configPath, newYamlContent, "utf8");
|
||||||
};
|
};
|
||||||
@@ -119,6 +111,18 @@ export const createPathMiddlewares = async (
|
|||||||
app: ApplicationNested,
|
app: ApplicationNested,
|
||||||
domain: Domain,
|
domain: Domain,
|
||||||
) => {
|
) => {
|
||||||
|
const { appName } = app;
|
||||||
|
const { uniqueConfigKey, internalPath, stripPath, path } = domain;
|
||||||
|
|
||||||
|
// Early return if there's no path middleware to create
|
||||||
|
const needsInternalPathMiddleware =
|
||||||
|
internalPath && internalPath !== "/" && internalPath !== path;
|
||||||
|
const needsStripPathMiddleware = stripPath && path && path !== "/";
|
||||||
|
|
||||||
|
if (!needsInternalPathMiddleware && !needsStripPathMiddleware) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let config: FileConfig;
|
let config: FileConfig;
|
||||||
|
|
||||||
if (app.serverId) {
|
if (app.serverId) {
|
||||||
@@ -135,9 +139,6 @@ export const createPathMiddlewares = async (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { appName } = app;
|
|
||||||
const { uniqueConfigKey, internalPath, stripPath, path } = domain;
|
|
||||||
|
|
||||||
if (!config.http) {
|
if (!config.http) {
|
||||||
config.http = { middlewares: {} };
|
config.http = { middlewares: {} };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user