Website: host vervangt het productie-basisadres in index.html door Website__PublicBaseUrl op testinstanties (Website:AuthoredBaseUrl)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 11:44:02 +01:00
co-authored by Claude Sonnet 5.5
parent 8af156c238
commit 32b98fea98
4 changed files with 60 additions and 0 deletions
@@ -82,6 +82,18 @@ public sealed class IndexHtmlInjector(
}
var html = await File.ReadAllTextAsync(indexPath, cancellationToken);
// A test instance points at itself: the authored production address becomes this instance's own.
// Only a configured PublicBaseUrl counts (never one derived from the request's Host header).
var configured = SpaSeoExtensions.BaseUrl(options.Value);
var authored = Uri.TryCreate(options.Value.AuthoredBaseUrl?.Trim(), UriKind.Absolute, out var authoredUri)
? authoredUri.GetLeftPart(UriPartial.Authority)
: null;
if (configured is not null && authored is not null
&& !string.Equals(configured, authored, StringComparison.OrdinalIgnoreCase))
{
html = html.Replace(authored, configured, StringComparison.Ordinal);
}
foreach (var (name, replacement) in markers)
{
html = html.Replace($"<!--{name}-->", replacement, StringComparison.Ordinal);
@@ -25,6 +25,14 @@ public sealed class WebsiteOptions
/// </summary>
public string? PublicBaseUrl { get; set; }
/// <summary>
/// The production address the website's static <c>index.html</c> is authored with (canonical, og:url, og:image,
/// twitter:image, JSON-LD url), e.g. <c>https://slpsoftware.nl</c>. When it differs from
/// <see cref="PublicBaseUrl"/> (a test instance), the host replaces it by <see cref="PublicBaseUrl"/> while
/// serving <c>index.html</c>, so a test site points at itself. Empty = no replacement; on production it is a no-op.
/// </summary>
public string? AuthoredBaseUrl { get; set; }
/// <summary>Paths listed in <c>/sitemap.xml</c> (SpaFallback sites), e.g. <c>/</c> and <c>/privacy</c>.</summary>
public SitemapOptions Sitemap { get; set; } = new();