refactor: enhance middleware removal logic in Traefik configuration

This commit is contained in:
Mauricio Siu
2025-10-05 12:07:19 -06:00
parent fc3fceb858
commit 7943c90d5d
@@ -195,6 +195,10 @@ export const removePathMiddlewares = async (
} }
} }
if (!config) {
return;
}
const { appName } = app; const { appName } = app;
if (config.http?.middlewares) { if (config.http?.middlewares) {
@@ -205,13 +209,12 @@ export const removePathMiddlewares = async (
delete config.http.middlewares[stripPrefixMiddleware]; delete config.http.middlewares[stripPrefixMiddleware];
} }
if (config?.http?.middlewares) { if (
// traefik will fail to start if the file contains middlewares entry but no middlewares are defined config?.http?.middlewares &&
const hasNoMiddlewares = Object.keys(config.http.middlewares).length === 0; Object.keys(config.http.middlewares).length === 0
if (hasNoMiddlewares) { ) {
// if there aren't any middlewares, remove the whole section // if there aren't any middlewares, remove the whole section
delete config.http.middlewares; delete config.http.middlewares;
}
} }
// // If http section is empty, remove it completely // // If http section is empty, remove it completely