| | | 1 | | using Elsa.Common.Multitenancy; |
| | | 2 | | using Elsa.Http; |
| | | 3 | | using Elsa.Http.Options; |
| | | 4 | | using JetBrains.Annotations; |
| | | 5 | | using Microsoft.Extensions.Options; |
| | | 6 | | |
| | | 7 | | namespace Elsa.Tenants.AspNetCore.Services; |
| | | 8 | | |
| | | 9 | | [UsedImplicitly] |
| | 0 | 10 | | public class TenantPrefixHttpEndpointBasePathProvider( |
| | 0 | 11 | | IOptions<HttpActivityOptions> options, |
| | 0 | 12 | | IEnumerable<ITenantResolver> tenantResolvers, |
| | 0 | 13 | | ITenantAccessor tenantAccessor) : IHttpEndpointBasePathProvider |
| | | 14 | | { |
| | | 15 | | public string GetBasePath() |
| | | 16 | | { |
| | 0 | 17 | | var baseUrl = options.Value.BaseUrl.ToString(); |
| | 0 | 18 | | var basePath = options.Value.BasePath?.ToString().TrimStart('/'); |
| | 0 | 19 | | var routePrefixTenantResolverIsEnabled = tenantResolvers.Any(x => x is RoutePrefixTenantResolver); |
| | | 20 | | |
| | 0 | 21 | | if(!routePrefixTenantResolverIsEnabled) |
| | 0 | 22 | | return (baseUrl + basePath).TrimEnd('/') + '/'; |
| | | 23 | | |
| | 0 | 24 | | var tenant = tenantAccessor.Tenant; |
| | 0 | 25 | | var tenantPrefix = tenant?.GetRoutePrefix()?.Trim('/'); |
| | | 26 | | |
| | 0 | 27 | | if(string.IsNullOrWhiteSpace(tenantPrefix)) |
| | 0 | 28 | | return (baseUrl + basePath).TrimEnd('/') + '/'; |
| | | 29 | | |
| | 0 | 30 | | var completeBaseUrl = new Uri(baseUrl + tenantPrefix + "/") + basePath; |
| | 0 | 31 | | return completeBaseUrl.TrimEnd('/') + '/'; |
| | | 32 | | } |
| | | 33 | | } |