fix: hotfix getting current port
This commit is contained in:
parent
e8e94e45a5
commit
053f01eec1
@ -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('/')}";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user