From 49811585c41e5bf3d8cb4c35466dc96b4c87e895 Mon Sep 17 00:00:00 2001 From: Meleki Date: Mon, 9 Mar 2026 06:48:33 +0100 Subject: [PATCH] fix: ServerSettings liest/schreibt jetzt Config vom ContentRoot statt AppContext.BaseDirectory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: systemd setzt WorkingDirectory=/app/gott (= ContentRoot), aber AppContext.BaseDirectory zeigt auf /app/gott/publish/. Dadurch existierten zwei appsettings.Production.json – .NET las die eine, die Server-Settings-UI schrieb die andere. Config-Änderungen wie PayloadLogging hatten daher keinen Effekt. Fix: ProductionConfigPath und FallbackConfigPath werden jetzt von app.Environment.ContentRootPath abgeleitet statt AppContext.BaseDirectory. --- Endpoints/ServerSettingsEndpoint.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Endpoints/ServerSettingsEndpoint.cs b/Endpoints/ServerSettingsEndpoint.cs index 94409a9..ad05311 100644 --- a/Endpoints/ServerSettingsEndpoint.cs +++ b/Endpoints/ServerSettingsEndpoint.cs @@ -13,11 +13,11 @@ namespace Gott.Endpoints; public static class ServerSettingsEndpoint { - private static readonly string ProductionConfigPath = - Path.Combine(AppContext.BaseDirectory, "appsettings.Production.json"); - - private static readonly string FallbackConfigPath = - Path.Combine(AppContext.BaseDirectory, "appsettings.json"); + // Pfade werden beim MapEndpoints gesetzt – basierend auf ContentRootPath, + // da .NET die Config-Dateien vom ContentRoot lädt (= WorkingDirectory), + // nicht von AppContext.BaseDirectory (= Executable-Verzeichnis). + private static string ProductionConfigPath; + private static string FallbackConfigPath; // Definiert alle konfigurierbaren Properties mit Typ und Standardwert private static readonly List Definitions = new List @@ -33,6 +33,10 @@ public static class ServerSettingsEndpoint public static void MapServerSettingsEndpoints(this WebApplication app) { + var contentRoot = app.Environment.ContentRootPath; + ProductionConfigPath = Path.Combine(contentRoot, "appsettings.Production.json"); + FallbackConfigPath = Path.Combine(contentRoot, "appsettings.json"); + app.MapGet("/api/admin/server-settings", HandleGet); app.MapPut("/api/admin/server-settings", HandleUpdate); }