fix: traefik needs middlewares to be empty/valid

This commit is contained in:
Bazyli Brzoska
2025-10-05 07:54:43 -07:00
parent 54853098a7
commit 080233a7cd
2 changed files with 17 additions and 1 deletions

View File

@@ -263,6 +263,14 @@ export const writeTraefikConfigRemote = async (
try {
const { DYNAMIC_TRAEFIK_PATH } = paths(true);
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);
await execAsyncRemote(serverId, `echo '${yamlStr}' > ${configPath}`);
} catch (e) {

View File

@@ -100,9 +100,17 @@ export const loadRemoteMiddlewares = async (serverId: string) => {
throw new Error(`File not found: ${configPath}`);
}
};
export const writeMiddleware = <T>(config: T) => {
export const writeMiddleware = (config: FileConfig) => {
const { DYNAMIC_TRAEFIK_PATH } = paths();
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);
writeFileSync(configPath, newYamlContent, "utf8");
};