diff --git a/Lombiq.Hosting.Tenants.Maintenance/Helpers/TenantUrlHelpers.cs b/Lombiq.Hosting.Tenants.Maintenance/Helpers/TenantUrlHelpers.cs index 7f7a214a..9da8aaf5 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Helpers/TenantUrlHelpers.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Helpers/TenantUrlHelpers.cs @@ -10,16 +10,15 @@ public static string ReplaceTenantName(string url, string tenantName) => url?.Replace("{TenantName}", tenantName.ToLowerInvariant()); #pragma warning restore CA1308 // Normalize strings to uppercase - public static string GetTenantUrl(string urlForDefaultTenant, string urlForAnyTenant, ShellSettings shellSettings) + public static string GetEvaluatedValueForTenant( + string valueForDefaultTenant, + string valueForAnyTenant, + ShellSettings shellSettings) { - var evaluatedRequestUrl = !string.IsNullOrEmpty(urlForAnyTenant) - ? ReplaceTenantName(urlForAnyTenant, shellSettings.Name) + var evaluatedValue = !string.IsNullOrEmpty(valueForAnyTenant) + ? ReplaceTenantName(valueForAnyTenant, shellSettings.Name) : string.Empty; - var defaultShellRequestUrl = - string.IsNullOrEmpty(urlForDefaultTenant) - ? evaluatedRequestUrl - : urlForDefaultTenant; - return shellSettings.IsDefaultShell() ? defaultShellRequestUrl : evaluatedRequestUrl; + return shellSettings.IsDefaultShell() ? valueForDefaultTenant : evaluatedValue; } } diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/UpdateShellRequestUrlMaintenanceOptions.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/UpdateShellRequestUrlMaintenanceOptions.cs index 4f23e550..f73f4318 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/UpdateShellRequestUrlMaintenanceOptions.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/UpdateShellRequestUrlMaintenanceOptions.cs @@ -6,4 +6,5 @@ public class UpdateShellRequestUrlMaintenanceOptions public string DefaultShellRequestUrl { get; set; } public string RequestUrl { get; set; } public string RequestUrlPrefix { get; set; } + public string DefaultShellRequestUrlPrefix { get; set; } } diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/UpdateShellRequestUrlsMaintenanceProvider.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/UpdateShellRequestUrlsMaintenanceProvider.cs index 2f5c7e53..503db90a 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/UpdateShellRequestUrlsMaintenanceProvider.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/UpdateShellRequestUrlsMaintenanceProvider.cs @@ -34,13 +34,14 @@ public override async Task ExecuteAsync(MaintenanceTaskExecutionContext context) var allShellSettings = await _shellSettingsManager.LoadSettingsAsync(); foreach (var shellSettings in allShellSettings) { - shellSettings.RequestUrlHost = TenantUrlHelpers.GetTenantUrl( + shellSettings.RequestUrlHost = TenantUrlHelpers.GetEvaluatedValueForTenant( _options.Value.DefaultShellRequestUrl, _options.Value.RequestUrl, shellSettings); - shellSettings.RequestUrlPrefix = TenantUrlHelpers.ReplaceTenantName( + shellSettings.RequestUrlPrefix = TenantUrlHelpers.GetEvaluatedValueForTenant( + _options.Value.DefaultShellRequestUrlPrefix, _options.Value.RequestUrlPrefix, - shellSettings.Name); + shellSettings); await _shellSettingsManager.SaveSettingsAsync(shellSettings); } diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/UpdateSiteUrlMaintenanceProvider.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/UpdateSiteUrlMaintenanceProvider.cs index a732507c..68931684 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/UpdateSiteUrlMaintenanceProvider.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/UpdateSiteUrlMaintenanceProvider.cs @@ -31,7 +31,7 @@ public override Task ShouldExecuteAsync(MaintenanceTaskExecutionContext co public override async Task ExecuteAsync(MaintenanceTaskExecutionContext context) { var siteSettings = await _siteService.LoadSiteSettingsAsync(); - siteSettings.BaseUrl = TenantUrlHelpers.GetTenantUrl( + siteSettings.BaseUrl = TenantUrlHelpers.GetEvaluatedValueForTenant( _options.Value.DefaultTenantSiteUrl, _options.Value.SiteUrl, _shellSettings); diff --git a/Lombiq.Hosting.Tenants.Maintenance/Readme.md b/Lombiq.Hosting.Tenants.Maintenance/Readme.md index 1c4decf0..4ace2cee 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Readme.md +++ b/Lombiq.Hosting.Tenants.Maintenance/Readme.md @@ -66,6 +66,7 @@ The following configuration options are available to set the shell request URLs: "IsEnabled": true, "DefaultShellRequestUrl": "domain.com", "RequestUrl": "{TenantName}.domain.com", + "DefaultShellRequestUrlPrefix": "", "RequestUrlPrefix": "{TenantName}" } }