using Microsoft.AspNetCore.Http; using System; using System.Linq; namespace Mirea.Api.Endpoint.Common.Services; public static class UrlHelper { public static string GetCurrentDomain(this HttpContext context) => context.Request.Headers["X-Forwarded-Host"].FirstOrDefault() ?? context.Request.Host.Host; private static string CreateSubPath(string? path) { if (string.IsNullOrEmpty(path)) return "/"; return "/" + path.Trim('/') + "/"; } public static string GetSubPath => CreateSubPath(Environment.GetEnvironmentVariable("ACTUAL_SUB_PATH")); public static string GetSubPathWithoutFirstApiName { get { var path = GetSubPath; if (string.IsNullOrEmpty(path) || path == "/") return CreateSubPath(null); var parts = path.Split('/', StringSplitOptions.RemoveEmptyEntries); if (parts[^1].Equals("api", StringComparison.CurrentCultureIgnoreCase)) parts = parts.Take(parts.Length - 1).ToArray(); return CreateSubPath(string.Join("/", parts)); } } public static string GetSubPathSwagger => CreateSubPath(Environment.GetEnvironmentVariable("SWAGGER_SUB_PATH")); }