mirror of
https://github.com/DorkSquadRR/DorkNet.git
synced 2026-10-25 23:18:44 -07:00
Fix notification URLs in HTTP deployments
Fixes #19 by making the December server advertise notification and service URLs with the configured deployment scheme.
This commit is contained in:
@@ -25,9 +25,9 @@ public class ConfigService(IConfiguration config, DomainConfig domain)
|
||||
return new RecRoomConfig
|
||||
{
|
||||
MessageOfTheDay = config["Server:MOTD"] ?? "Welcome to the private server!",
|
||||
CdnBaseUri = $"https://{domain.Sub("cdn")}",
|
||||
CdnBaseUri = domain.Url("cdn"),
|
||||
PhotonConfig = photon,
|
||||
ServiceUrls = BuildServiceUrlMap(apex),
|
||||
ServiceUrls = BuildServiceUrlMap(domain),
|
||||
ConfigTable = new Dictionary<string, string>
|
||||
{
|
||||
// Season keys the 2019/2020 client checks at startup
|
||||
@@ -110,12 +110,14 @@ public class ConfigService(IConfiguration config, DomainConfig domain)
|
||||
/// <see cref="DomainConfig.Apex"/>) so the map stays a single
|
||||
/// source of truth.</summary>
|
||||
public static Dictionary<string, string> BuildServiceUrlMap(string apex)
|
||||
=> BuildServiceUrlMap(new DomainConfig(apex));
|
||||
|
||||
public static Dictionary<string, string> BuildServiceUrlMap(DomainConfig domain)
|
||||
{
|
||||
var map = new Dictionary<string, string>(ServiceSubdomains.Length);
|
||||
foreach (var (service, sub) in ServiceSubdomains)
|
||||
{
|
||||
var host = string.IsNullOrEmpty(sub) ? apex : $"{sub}.{apex}";
|
||||
map[service] = $"https://{host}";
|
||||
map[service] = domain.Url(sub);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -11,8 +11,28 @@ namespace DorkNet.Server.Services;
|
||||
public sealed class DomainConfig
|
||||
{
|
||||
public string Apex { get; }
|
||||
public DomainConfig(string apex) { Apex = apex; }
|
||||
public string Scheme { get; }
|
||||
|
||||
public DomainConfig(string apex, string scheme = "https")
|
||||
{
|
||||
Apex = apex;
|
||||
Scheme = NormalizeScheme(scheme);
|
||||
}
|
||||
|
||||
public string Sub(string prefix) => $"{prefix}.{Apex}";
|
||||
public string Url(string prefix, string path = "")
|
||||
{
|
||||
var host = string.IsNullOrEmpty(prefix) ? Apex : Sub(prefix);
|
||||
if (string.IsNullOrEmpty(path)) return $"{Scheme}://{host}";
|
||||
return $"{Scheme}://{host}{(path.StartsWith('/') ? path : "/" + path)}";
|
||||
}
|
||||
|
||||
public static bool MatchesSubdomain(string host, string prefix)
|
||||
=> 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";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user