diff --git a/Endpoint/Common/Services/UrlHelper.cs b/Endpoint/Common/Services/UrlHelper.cs index 0c2a4f5..a539c41 100644 --- a/Endpoint/Common/Services/UrlHelper.cs +++ b/Endpoint/Common/Services/UrlHelper.cs @@ -11,6 +11,9 @@ public static class UrlHelper public static string GetCurrentDomain(this HttpContext context) => 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) { @@ -47,7 +50,7 @@ public static class UrlHelper var scheme = GetCurrentScheme(context); 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; return $"{scheme}://{domain}{portString}{GetSubPathWithoutFirstApiName}{apiPath.Trim('/')}";