Normalize base address in Node class to ensure consistent URI formatting
CI / Backend (build + test) (push) Successful in 1m25s
CI / Frontend (lint + typecheck + build) (push) Successful in 33s

- Implemented `NormalizeBaseAddress` method to add a trailing slash to the `BaseAddress` when necessary, preventing issues with relative path merging in 3x-ui deployments.
- Updated `Register` and `UpdateAddress` methods to utilize the normalization logic, ensuring that both methods handle base address input consistently.
- Added unit tests to verify the normalization behavior for various input scenarios, enhancing the reliability of node address management.
- Updated domain model documentation to reflect the new normalization behavior for `BaseAddress`.
This commit is contained in:
Leonid Pershin committed 2026-07-23 10:55:17 +03:00
1 parent c4bc6ff04b
commit 2f6bb26e97
3 files changed
+41 -2

No files matched your search

+11 -2
View File
@@ -34,7 +34,7 @@ public sealed class Node : Entity
{
Id = Guid.NewGuid(),
Name = name,
BaseAddress = baseAddress,
BaseAddress = NormalizeBaseAddress(baseAddress),
Credentials = credentials,
Location = location,
Status = NodeStatus.Unknown,
@@ -54,9 +54,18 @@ public sealed class Node : Entity
if (!baseAddress.IsAbsoluteUri)
throw new DomainException("Адрес ноды должен быть абсолютным URI.");
BaseAddress = baseAddress;
BaseAddress = NormalizeBaseAddress(baseAddress);
}
/// <summary>3x-ui часто разворачивается за нестандартным base path (`webBasePath`, напр.
/// `/benis`) — без завершающего слэша относительное объединение пути (RFC 3986 merge) отбрасывает
/// последний сегмент базы вместо добавления к нему, роняя `/benis` из итогового URL. Нормализуем
/// один раз при сохранении, чтобы админ мог вводить адрес и с завершающим слэшем, и без него.</summary>
private static Uri NormalizeBaseAddress(Uri baseAddress) =>
baseAddress.AbsolutePath.EndsWith('/')
? baseAddress
: new UriBuilder(baseAddress) { Path = baseAddress.AbsolutePath + "/" }.Uri;
public void UpdateCredentials(NodeCredentials credentials) => Credentials = credentials;
public void Enable() => IsEnabled = true;