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 ff55baa0c5
commit 98fa7b89cf
4 changed files with 87 additions and 8 deletions
+18 -3
View File
@@ -12,14 +12,22 @@ public sealed class DomainConfig
{
public string Apex { get; }
public string Scheme { get; }
public string HostStyle { get; }
public bool UsesHyphenSubdomains => HostStyle == "hyphen";
public DomainConfig(string apex, string scheme = "https")
public DomainConfig(string apex, string scheme = "https", string hostStyle = "dot")
{
Apex = apex;
Scheme = NormalizeScheme(scheme);
HostStyle = NormalizeHostStyle(hostStyle);
}
public string Sub(string prefix)
{
if (string.IsNullOrWhiteSpace(prefix)) return Apex;
return UsesHyphenSubdomains ? $"{prefix}-{Apex}" : $"{prefix}.{Apex}";
}
public string Sub(string prefix) => $"{prefix}.{Apex}";
public string Url(string prefix, string path = "")
{
var host = string.IsNullOrEmpty(prefix) ? Apex : Sub(prefix);
@@ -28,11 +36,18 @@ public sealed class DomainConfig
}
public static bool MatchesSubdomain(string host, string prefix)
=> host.StartsWith(prefix + ".", StringComparison.OrdinalIgnoreCase);
=> host.StartsWith(prefix + ".", StringComparison.OrdinalIgnoreCase)
|| host.StartsWith(prefix + "-", StringComparison.OrdinalIgnoreCase);
private static string NormalizeScheme(string? value)
{
var scheme = string.IsNullOrWhiteSpace(value) ? "https" : value.Trim().TrimEnd(':', '/', '\\').ToLowerInvariant();
return scheme is "http" or "https" ? scheme : "https";
}
private static string NormalizeHostStyle(string? value)
{
var style = string.IsNullOrWhiteSpace(value) ? "dot" : value.Trim().ToLowerInvariant();
return style is "hyphen" or "dash" or "flat" ? "hyphen" : "dot";
}
}