Fase B1: Website:Mode via configuratie (ASF kiest in appsettings), Api = alle-modules-compositie; flaky SMTP-test gerepareerd
- CmsHostOptions.ResolveWebsiteMode: Website:Mode wint van de code, default SpaFallback, onbekende waarde stopt de host. - ASF: Website:Mode=PrerenderedPages in appsettings.json, Program.cs zonder eigen modus. - SlpModularCms.Api verwijst nu ook naar Offerings en Contact met generieke default-config (Website/Email/App/Contact/RateLimiting). - SmtpFailureTests: '535' als los getal, niet als substring van een willekeurige poort. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -59,7 +59,8 @@ public static class CmsHost
|
||||
builder.Services.AddCmsSecurityHeaders(builder.Configuration);
|
||||
builder.Services.AddCmsObservability(builder.Configuration);
|
||||
|
||||
if (options.WebsiteMode == WebsiteMode.PrerenderedPages)
|
||||
var websiteMode = options.ResolveWebsiteMode(builder.Configuration);
|
||||
if (websiteMode == WebsiteMode.PrerenderedPages)
|
||||
{
|
||||
builder.Services.AddCmsWebsite(builder.Configuration);
|
||||
}
|
||||
@@ -96,6 +97,7 @@ public static class CmsHost
|
||||
/// </summary>
|
||||
public static void ConfigurePipeline(WebApplication app, ModuleOrchestrator orchestrator, CmsHostOptions options)
|
||||
{
|
||||
var websiteMode = options.ResolveWebsiteMode(app.Configuration);
|
||||
// Bring the Core schema up to date before serving any traffic. Runs before the module
|
||||
// middleware below, because the Data Protection keys table lives in this context and the
|
||||
// modules resolve an IDataProtector as soon as they start. Fails fast: a host that cannot
|
||||
@@ -121,7 +123,7 @@ public static class CmsHost
|
||||
|
||||
// SpaFallback sites: X-Robots-Tag on test hosts and generated robots.txt / sitemap.xml. After the
|
||||
// security headers (so these answers carry them) and before the static files short-circuit.
|
||||
if (options.WebsiteMode == WebsiteMode.SpaFallback)
|
||||
if (websiteMode == WebsiteMode.SpaFallback)
|
||||
{
|
||||
app.UseCmsSpaSeo();
|
||||
}
|
||||
@@ -142,12 +144,12 @@ public static class CmsHost
|
||||
// wwwroot/admin/index.html + assets -> CMS admin build (see frontend/, copied in on publish)
|
||||
// Registered before the module middleware below: static files short-circuit the pipeline, so
|
||||
// anything that must observe them has to come first.
|
||||
app.UseCmsStaticContent(options.WebsiteMode);
|
||||
app.UseCmsStaticContent(websiteMode);
|
||||
|
||||
// WebsiteMode.PrerenderedPages: the website replaces the SPA-style website mount, at the same
|
||||
// position and for the same reason (it answers before the module middleware and the API).
|
||||
// It never handles /admin, /api/v1 or /health.
|
||||
if (options.WebsiteMode == WebsiteMode.PrerenderedPages)
|
||||
if (websiteMode == WebsiteMode.PrerenderedPages)
|
||||
{
|
||||
app.UseCmsPrerenderedSite();
|
||||
}
|
||||
@@ -177,11 +179,11 @@ public static class CmsHost
|
||||
|
||||
// SPA fallbacks so client-side routes (e.g. /admin/dashboard) resolve to the right index.html
|
||||
// instead of 404ing. The "nonfile" constraint keeps genuinely missing assets (e.g. /admin/assets/x.js) as 404s.
|
||||
app.MapCmsSpaFallbacks(options.WebsiteMode);
|
||||
app.MapCmsSpaFallbacks(websiteMode);
|
||||
|
||||
// WebsiteMode.PrerenderedPages: lowest-priority endpoint, so unknown website paths get
|
||||
// 404.html with status 404 only AFTER every API route and the admin fallback had their turn.
|
||||
if (options.WebsiteMode == WebsiteMode.PrerenderedPages)
|
||||
if (websiteMode == WebsiteMode.PrerenderedPages)
|
||||
{
|
||||
app.MapCmsWebsiteNotFound();
|
||||
}
|
||||
|
||||
@@ -26,6 +26,31 @@ public enum WebsiteMode
|
||||
/// </remarks>
|
||||
public sealed class CmsHostOptions
|
||||
{
|
||||
/// <summary>How the public website is served. Defaults to <see cref="WebsiteMode.SpaFallback"/>.</summary>
|
||||
/// <summary>
|
||||
/// How the public website is served when the configuration does not say. Defaults to
|
||||
/// <see cref="WebsiteMode.SpaFallback"/>. The configuration value <c>Website:Mode</c> wins over this
|
||||
/// (see <see cref="ResolveWebsiteMode"/>), so a site picks its mode in its appsettings.json and a test
|
||||
/// can run the same host in either mode.
|
||||
/// </summary>
|
||||
public WebsiteMode WebsiteMode { get; init; } = WebsiteMode.SpaFallback;
|
||||
|
||||
/// <summary>
|
||||
/// The mode to use: <c>Website:Mode</c> (<c>SpaFallback</c> or <c>PrerenderedPages</c>, case-insensitive)
|
||||
/// when set, otherwise <see cref="WebsiteMode"/>. An unknown value stops the host at start-up instead of
|
||||
/// silently serving the website the wrong way.
|
||||
/// </summary>
|
||||
public WebsiteMode ResolveWebsiteMode(Microsoft.Extensions.Configuration.IConfiguration configuration)
|
||||
{
|
||||
var value = configuration["Website:Mode"];
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
return WebsiteMode;
|
||||
|
||||
// Names only: a bare number would also parse, and "1" is not something a person means by a mode.
|
||||
var name = Enum.GetNames<WebsiteMode>().FirstOrDefault(n => string.Equals(n, value.Trim(), StringComparison.OrdinalIgnoreCase));
|
||||
if (name is not null)
|
||||
return Enum.Parse<WebsiteMode>(name);
|
||||
|
||||
throw new InvalidOperationException(
|
||||
$"Website:Mode '{value}' is not valid; use '{nameof(WebsiteMode.SpaFallback)}' or '{nameof(WebsiteMode.PrerenderedPages)}'.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user