refactor: AppPaths.WwwRoot – zentrale wwwroot-Pfadauflösung
- Neue statische Klasse AppPaths mit WwwRoot-Property - Dev-Modus: ../../../wwwroot (Quell-Verzeichnis) - Publish-Modus: Fallback auf BaseDirectory/wwwroot - Program.cs + RemoteEndpoint.cs nutzen AppPaths statt eigener Logik
This commit is contained in:
1 parent
49ef6bedc6
commit
ab64a843fc
3 files changed
+32
-4
No files matched your search
@@ -241,7 +241,7 @@ public static class RemoteEndpoint
|
|||||||
|
|
||||||
private static async Task<IResult> ServeScript(HttpContext ctx)
|
private static async Task<IResult> ServeScript(HttpContext ctx)
|
||||||
{
|
{
|
||||||
var scriptPath = Path.Combine(AppContext.BaseDirectory, "wwwroot", "remote.ps1");
|
var scriptPath = Path.Combine(AppPaths.WwwRoot, "remote.ps1");
|
||||||
if (!File.Exists(scriptPath))
|
if (!File.Exists(scriptPath))
|
||||||
return Results.NotFound("Script nicht gefunden");
|
return Results.NotFound("Script nicht gefunden");
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -138,10 +138,10 @@ await app.Services.GetRequiredService<OpenAiService>().LoadModelsAsync();
|
|||||||
app.UseWebSockets();
|
app.UseWebSockets();
|
||||||
|
|
||||||
// wwwroot: Quell-Verzeichnis bevorzugen (Live-Änderungen ohne Publish)
|
// wwwroot: Quell-Verzeichnis bevorzugen (Live-Änderungen ohne Publish)
|
||||||
var devWwwroot = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "..", "..", "..", "wwwroot"));
|
AppPaths.Initialize();
|
||||||
if (Directory.Exists(devWwwroot))
|
if (AppPaths.WwwRoot != Path.Combine(AppContext.BaseDirectory, "wwwroot"))
|
||||||
{
|
{
|
||||||
var fileProvider = new PhysicalFileProvider(devWwwroot);
|
var fileProvider = new PhysicalFileProvider(AppPaths.WwwRoot);
|
||||||
app.UseDefaultFiles(new DefaultFilesOptions { FileProvider = fileProvider });
|
app.UseDefaultFiles(new DefaultFilesOptions { FileProvider = fileProvider });
|
||||||
app.UseStaticFiles(new StaticFileOptions { FileProvider = fileProvider });
|
app.UseStaticFiles(new StaticFileOptions { FileProvider = fileProvider });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Gott.Services;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Zentrale Pfade der Anwendung. Werden beim Start in Program.cs gesetzt.
|
||||||
|
/// </summary>
|
||||||
|
public static class AppPaths
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Absoluter Pfad zum wwwroot-Verzeichnis.
|
||||||
|
/// Im Dev-Modus das Quell-Verzeichnis (../../../wwwroot),
|
||||||
|
/// im Publish-Modus das Verzeichnis neben der Executable.
|
||||||
|
/// </summary>
|
||||||
|
public static string WwwRoot { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initialisiert die Pfade. Wird einmal beim Start aufgerufen.
|
||||||
|
/// </summary>
|
||||||
|
public static void Initialize()
|
||||||
|
{
|
||||||
|
var devPath = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "..", "..", "..", "wwwroot"));
|
||||||
|
WwwRoot = Directory.Exists(devPath)
|
||||||
|
? devPath
|
||||||
|
: Path.Combine(AppContext.BaseDirectory, "wwwroot");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user