Voeg WebsiteMode.PrerenderedPages toe: nginx-gelijke serving van een voorgerenderde website

- Pure WebsitePathResolver (canonieke 301's, echte 404, dotfiles geweigerd, gereserveerde prefixes)
- PrerenderedSiteMiddleware, 404-fallback na de API-routes, gzip, Cache-Control, NoIndex/robots.txt
- Beleid StrictSite met eigen AllowedSite*Origins; volledige headerset op alle websiteresponses
- Tests: voorbeelden, FsCheck-properties en integratietests op een in-memory server

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-06 15:52:04 +01:00
co-authored by Claude Sonnet 5.5
parent d9cc539481
commit 7d21d9024a
25 changed files with 1859 additions and 23 deletions
+23 -2
View File
@@ -6,6 +6,7 @@ using Microsoft.Extensions.Logging;
using SlpModularCms.Core.Hosting.Health;
using SlpModularCms.Core.Hosting.Observability;
using SlpModularCms.Core.Hosting.Security;
using SlpModularCms.Core.Hosting.Website;
using Scalar.AspNetCore;
namespace SlpModularCms.Core.Hosting;
@@ -56,6 +57,11 @@ public static class CmsHost
builder.Services.AddCmsSecurityHeaders(builder.Configuration);
builder.Services.AddCmsObservability(builder.Configuration);
if (options.WebsiteMode == WebsiteMode.PrerenderedPages)
{
builder.Services.AddCmsWebsite(builder.Configuration);
}
// Registered BEFORE module services: modules must not configure Data Protection themselves,
// because a later registration would override this persistent key store (see
// DataProtectionExtensions).
@@ -117,7 +123,15 @@ 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();
app.UseCmsStaticContent(options.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)
{
app.UseCmsPrerenderedSite();
}
app.UseCors();
@@ -144,6 +158,13 @@ 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();
app.MapCmsSpaFallbacks(options.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)
{
app.MapCmsWebsiteNotFound();
}
}
}