feat: add calculate correct api url
This commit is contained in:
parent
6b5eda7756
commit
713bbfa16f
@ -6,6 +6,9 @@ namespace Mirea.Api.Endpoint.Common.Services;
|
|||||||
|
|
||||||
public static class UrlHelper
|
public static class UrlHelper
|
||||||
{
|
{
|
||||||
|
public static string GetCurrentScheme(this HttpContext context) =>
|
||||||
|
context.Request.Headers["X-Forwarded-Proto"].FirstOrDefault() ?? context.Request.Scheme;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
@ -38,4 +41,15 @@ public static class UrlHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static string GetSubPathSwagger => CreateSubPath(Environment.GetEnvironmentVariable("SWAGGER_SUB_PATH"));
|
public static string GetSubPathSwagger => CreateSubPath(Environment.GetEnvironmentVariable("SWAGGER_SUB_PATH"));
|
||||||
|
|
||||||
|
public static string GetApiUrl(this HttpContext context, string apiPath = "")
|
||||||
|
{
|
||||||
|
var scheme = GetCurrentScheme(context);
|
||||||
|
var domain = GetCurrentDomain(context).TrimEnd('/');
|
||||||
|
|
||||||
|
var port = context.Request.Host.Port;
|
||||||
|
var portString = port.HasValue && port != 80 && port != 443 ? $":{port}" : string.Empty;
|
||||||
|
|
||||||
|
return $"{scheme}://{domain}{portString}{GetSubPathWithoutFirstApiName}{apiPath.Trim('/')}";
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user