mirror of
https://github.com/CannedNet/CannedNet.git
synced 2026-10-25 23:18:54 -07:00
OKAY NOW IT ACTUALLY WORKS
This commit is contained in:
@@ -1,38 +1,38 @@
|
|||||||
{
|
{
|
||||||
"Accounts": "https://cannednet.lapis.codes/accounts",
|
"Accounts": "http://localhost:5000/accounts",
|
||||||
"AI": "https://cannednet.lapis.codes/ai",
|
"AI": "http://localhost:5000/ai",
|
||||||
"API": "https://cannednet.lapis.codes/api",
|
"API": "http://localhost:5000/api",
|
||||||
"Auth": "https://cannednet.lapis.codes/auth",
|
"Auth": "http://localhost:5000/auth",
|
||||||
"BugReporting": "https://cannednet.lapis.codes/bugreporting",
|
"BugReporting": "http://localhost:5000/bugreporting",
|
||||||
"Cards": "https://cannednet.lapis.codes/cards",
|
"Cards": "http://localhost:5000/cards",
|
||||||
"CDN": "https://cannednet.lapis.codes/cdn",
|
"CDN": "http://localhost:5000/cdn",
|
||||||
"Chat": "https://cannednet.lapis.codes/chat",
|
"Chat": "http://localhost:5000/chat",
|
||||||
"Clubs": "https://cannednet.lapis.codes/clubs",
|
"Clubs": "http://localhost:5000/clubs",
|
||||||
"CMS": "https://cannednet.lapis.codes/cms",
|
"CMS": "http://localhost:5000/cms",
|
||||||
"Commerce": "https://cannednet.lapis.codes/commerce",
|
"Commerce": "http://localhost:5000/commerce",
|
||||||
"Data": "https://cannednet.lapis.codes/data",
|
"Data": "http://localhost:5000/data",
|
||||||
"DataCollection": "https://cannednet.lapis.codes/datacollection",
|
"DataCollection": "http://localhost:5000/datacollection",
|
||||||
"Discovery": "https://cannednet.lapis.codes/discovery",
|
"Discovery": "http://localhost:5000/discovery",
|
||||||
"Econ": "https://cannednet.lapis.codes/econ",
|
"Econ": "http://localhost:5000/econ",
|
||||||
"GameLogs": "https://cannednet.lapis.codes/gamelogs",
|
"GameLogs": "http://localhost:5000/gamelogs",
|
||||||
"Geo": "https://cannednet.lapis.codes/geo",
|
"Geo": "http://localhost:5000/geo",
|
||||||
"Images": "https://cannednet.lapis.codes/img",
|
"Images": "http://localhost:5000/img",
|
||||||
"Leaderboard": "https://cannednet.lapis.codes/leaderboard",
|
"Leaderboard": "http://localhost:5000/leaderboard",
|
||||||
"Link": "https://cannednet.lapis.codes/link",
|
"Link": "http://localhost:5000/link",
|
||||||
"Lists": "https://cannednet.lapis.codes/lists",
|
"Lists": "http://localhost:5000/lists",
|
||||||
"Matchmaking": "https://cannednet.lapis.codes/match",
|
"Matchmaking": "http://localhost:5000/match",
|
||||||
"Moderation": "https://cannednet.lapis.codes/moderation",
|
"Moderation": "http://localhost:5000/moderation",
|
||||||
"Notifications": "https://cannednet.lapis.codes",
|
"Notifications": "http://localhost:5000",
|
||||||
"PlatformNotifications": "https://cannednet.lapis.codes",
|
"PlatformNotifications": "http://localhost:5000",
|
||||||
"PlayerSettings": "https://cannednet.lapis.codes/playersettings",
|
"PlayerSettings": "http://localhost:5000/playersettings",
|
||||||
"RoomComments": "https://cannednet.lapis.codes/roomcomments",
|
"RoomComments": "http://localhost:5000/roomcomments",
|
||||||
"RoomieIntegrations": "https://cannednet.lapis.codes/roomieintegrations",
|
"RoomieIntegrations": "http://localhost:5000/roomieintegrations",
|
||||||
"Rooms": "https://cannednet.lapis.codes/rooms",
|
"Rooms": "http://localhost:5000/rooms",
|
||||||
"Storage": "https://cannednet.lapis.codes/storage",
|
"Storage": "http://localhost:5000/storage",
|
||||||
"Strings": "https://cannednet.lapis.codes/strings",
|
"Strings": "http://localhost:5000/strings",
|
||||||
"StringsCDN": "https://cannednet.lapis.codes/stringscdn",
|
"StringsCDN": "http://localhost:5000/stringscdn",
|
||||||
"Studio": "https://cannednet.lapis.codes/studio",
|
"Studio": "http://localhost:5000/studio",
|
||||||
"Thorn": "https://cannednet.lapis.codes/thorn",
|
"Thorn": "http://localhost:5000/thorn",
|
||||||
"Videos": "https://cannednet.lapis.codes/videos",
|
"Videos": "http://localhost:5000/videos",
|
||||||
"WWW": "https://cannednet.lapis.codes"
|
"WWW": "http://localhost:5000"
|
||||||
}
|
}
|
||||||
@@ -51,42 +51,39 @@ public class ConfigService
|
|||||||
if (endpoints == null || endpoints.Count == 0)
|
if (endpoints == null || endpoints.Count == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var currentBase = DetectBaseUrl(endpoints);
|
if (!Uri.TryCreate(configBase + "/", UriKind.Absolute, out var configUri))
|
||||||
if (currentBase == null)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (string.Equals(currentBase, configBase, StringComparison.OrdinalIgnoreCase))
|
var configOrigin = $"{configUri.Scheme}://{configUri.Host}{(configUri.IsDefaultPort ? "" : $":{configUri.Port}")}";
|
||||||
return;
|
|
||||||
|
|
||||||
var updated = new Dictionary<string, string>(endpoints.Count);
|
var updated = new Dictionary<string, string>(endpoints.Count);
|
||||||
|
var changed = false;
|
||||||
|
|
||||||
foreach (var (key, url) in endpoints)
|
foreach (var (key, url) in endpoints)
|
||||||
{
|
{
|
||||||
if (url.StartsWith(currentBase, StringComparison.OrdinalIgnoreCase))
|
if (string.IsNullOrEmpty(url) || !Uri.TryCreate(url, UriKind.Absolute, out var uri))
|
||||||
{
|
{
|
||||||
var path = url[currentBase.Length..];
|
updated[key] = url;
|
||||||
updated[key] = configBase + path;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
var urlOrigin = $"{uri.Scheme}://{uri.Host}{(uri.IsDefaultPort ? "" : $":{uri.Port}")}";
|
||||||
|
if (string.Equals(urlOrigin, configOrigin, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
updated[key] = url;
|
updated[key] = url;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var path = url[urlOrigin.Length..];
|
||||||
|
updated[key] = configOrigin + path;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (changed)
|
||||||
File.WriteAllText(EndpointsPath, JsonSerializer.Serialize(updated, Indented));
|
File.WriteAllText(EndpointsPath, JsonSerializer.Serialize(updated, Indented));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string? DetectBaseUrl(Dictionary<string, string> endpoints)
|
|
||||||
{
|
|
||||||
foreach (var url in endpoints.Values)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(url))
|
|
||||||
continue;
|
|
||||||
if (Uri.TryCreate(url, UriKind.Absolute, out var uri))
|
|
||||||
return $"{uri.Scheme}://{uri.Host}{(uri.IsDefaultPort ? "" : $":{uri.Port}")}";
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static AppConfig CreateDefaultConfig()
|
private static AppConfig CreateDefaultConfig()
|
||||||
{
|
{
|
||||||
return new AppConfig
|
return new AppConfig
|
||||||
|
|||||||
Reference in New Issue
Block a user