feat: Enhance domain configuration to support hyphen subdomains and update related methods

This commit is contained in:
Alexa
2026-06-25 11:46:34 +03:00
parent a68e9b169f
commit 9c921715c7
4 changed files with 87 additions and 8 deletions
@@ -54,7 +54,7 @@ public static class MiddlewarePipelineExtensions
// Public-facing site at the apex (e.g. localhost + www variant).
// React-router routes are client-side so spaFallback must be true.
app.MountStaticHost(domainCfg.Apex, "site", spaFallback: true);
app.MountStaticHost($"www.{domainCfg.Apex}", "site", spaFallback: true);
app.MountStaticHost(domainCfg.Sub("www"), "site", spaFallback: true);
// Old feed.* subdomain kept as legacy; new visitors land on the apex.
app.MountStaticHost(domainCfg.Sub("feed"), "feed");
@@ -115,7 +115,23 @@ public static class ServiceCollectionExtensions
?? Environment.GetEnvironmentVariable("DORKNET_DOMAIN")
?? "localhost";
var scheme = builder.Configuration["Domain:Scheme"] ?? "https";
var allowedHosts = new List<string> { apex, $"*.{apex}", "localhost", "127.0.0.1" };
var hostStyle =
builder.Configuration["Domain:HostStyle"]
?? Environment.GetEnvironmentVariable("DORKNET_DOMAIN_STYLE")
?? "dot";
var domain = new DomainConfig(apex, scheme, hostStyle);
var allowedHosts = new List<string> { apex, "localhost", "127.0.0.1" };
if (domain.UsesHyphenSubdomains)
{
allowedHosts.AddRange(KnownServiceSubdomains
.Where(s => !string.IsNullOrWhiteSpace(s))
.Select(domain.Sub));
allowedHosts.Add(domain.Sub("www"));
}
else
{
allowedHosts.Add($"*.{apex}");
}
var bootstrapApex = builder.Configuration["Domain:BootstrapApex"];
if (!string.IsNullOrWhiteSpace(bootstrapApex))
{
@@ -123,16 +139,57 @@ public static class ServiceCollectionExtensions
allowedHosts.Add($"*.{bootstrapApex}");
}
builder.Services.AddSingleton(new DomainConfig(apex, scheme));
builder.Services.AddSingleton(domain);
builder.Services.Configure<Microsoft.AspNetCore.HostFiltering.HostFilteringOptions>(opt =>
{
opt.AllowedHosts = allowedHosts.Distinct(StringComparer.OrdinalIgnoreCase).ToArray();
opt.AllowEmptyHosts = true;
opt.IncludeFailureMessage = true;
});
Console.WriteLine($"[domain] apex={apex}, allowedHosts=[{string.Join(", ", allowedHosts)}]");
Console.WriteLine($"[domain] apex={apex}, style={domain.HostStyle}, allowedHosts=[{string.Join(", ", allowedHosts)}]");
}
private static readonly string[] KnownServiceSubdomains =
{
"admin",
"api",
"accounts",
"auth",
"bugreporting",
"cards",
"cdn",
"chat",
"clubs",
"cms",
"commerce",
"data",
"datacollection",
"discovery",
"econ",
"feed",
"gamelogs",
"geo",
"img",
"leaderboard",
"link",
"lists",
"match",
"moderation",
"notify",
"ns",
"platformnotifications",
"playersettings",
"roomcomments",
"roomieintegrations",
"rooms",
"storage",
"strings",
"strings-cdn",
"studio",
"thorn",
"videos",
};
// ── Services ──────────────────────────────────────────────────────────────
private static void AddCoreServices(IServiceCollection services)
{