Added preprocessor directives to handle both development & release versions

This commit is contained in:
Thorsten Sommer 2024-05-18 21:50:46 +02:00
parent 8dd6a2f898
commit cb3bb42aa4
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 27 additions and 1 deletions

View File

@ -38,15 +38,28 @@ builder.Services.AddRazorComponents()
var port = args.Length > 0 ? args[0] : "5000";
builder.WebHost.UseUrls($"http://localhost:{port}");
var fileProvider = new ManifestEmbeddedFileProvider(Assembly.GetAssembly(type: typeof(Program))!, "wwwroot");
#if DEBUG
builder.WebHost.UseWebRoot("wwwroot");
builder.WebHost.UseStaticWebAssets();
#endif
var app = builder.Build();
app.Use(Redirect.HandlerContentAsync);
#if DEBUG
app.UseStaticFiles();
#else
var fileProvider = new ManifestEmbeddedFileProvider(Assembly.GetAssembly(type: typeof(Program))!, "wwwroot");
app.UseDeveloperExceptionPage();
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = fileProvider,
RequestPath = string.Empty,
});
#endif
app.UseAntiforgery();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();

View File

@ -14,12 +14,25 @@ internal static class Redirect
return;
}
#if DEBUG
if (path.StartsWith(SYSTEM, StringComparison.InvariantCulture))
{
context.Response.Redirect(path.Replace(SYSTEM, CONTENT), true, true);
return;
}
#else
if (path.StartsWith(CONTENT, StringComparison.InvariantCulture))
{
context.Response.Redirect(path.Replace(CONTENT, SYSTEM), true, true);
return;
}
#endif
await nextHandler();
}