fix: hotfix getting current port
All checks were successful
.NET Test Pipeline / build-and-test (push) Successful in 1m33s
Build and Deploy Docker Container / build-and-deploy (push) Successful in 1m35s

This commit is contained in:
Polianin Nikita 2024-12-23 06:56:01 +03:00
parent e8e94e45a5
commit 053f01eec1

View File

@ -11,6 +11,9 @@ public static class UrlHelper
public static string GetCurrentDomain(this HttpContext context) => public static string GetCurrentDomain(this HttpContext context) =>
context.Request.Headers["X-Forwarded-Host"].FirstOrDefault() ?? context.Request.Host.Host; context.Request.Headers["X-Forwarded-Host"].FirstOrDefault() ?? context.Request.Host.Host;
public static int? GetCurrentPort(this HttpContext context) =>
string.IsNullOrEmpty(context.Request.Headers["X-Forwarded-Port"].FirstOrDefault()) ? context.Request.Host.Port :
int.Parse(context.Request.Headers["X-Forwarded-Port"].First()!);
private static string CreateSubPath(string? path) private static string CreateSubPath(string? path)
{ {
@ -47,7 +50,7 @@ public static class UrlHelper
var scheme = GetCurrentScheme(context); var scheme = GetCurrentScheme(context);
var domain = GetCurrentDomain(context).TrimEnd('/').Replace("localhost", "127.0.0.1"); var domain = GetCurrentDomain(context).TrimEnd('/').Replace("localhost", "127.0.0.1");
var port = context.Request.Host.Port; var port = GetCurrentPort(context);
var portString = port.HasValue && port != 80 && port != 443 ? $":{port}" : string.Empty; var portString = port.HasValue && port != 80 && port != 443 ? $":{port}" : string.Empty;
return $"{scheme}://{domain}{portString}{GetSubPathWithoutFirstApiName}{apiPath.Trim('/')}"; return $"{scheme}://{domain}{portString}{GetSubPathWithoutFirstApiName}{apiPath.Trim('/')}";