From 310400b9e731fb960bd970e2684f242c1b490617 Mon Sep 17 00:00:00 2001 From: masoodafar-web Date: Wed, 13 May 2026 23:52:16 +0330 Subject: [PATCH] refactor: simplify configuration handling for CMS URL - Removed CmsServerBaseUrl utility class and updated references to directly access GwUrl from configuration. - Adjusted frontoffice-deployment.yaml to remove CmsInternalBaseUrl environment variable. - Updated appsettings for staging and main environments to reflect the correct CMS service URLs. - Ensured consistent handling of GwUrl in TokenNotificationService and AddGrpcServices methods. --- k8s/staging/frontoffice-deployment.yaml | 5 +---- src/FrontOffice.Main/ConfigureServices.cs | 4 +--- .../Utilities/CmsServerBaseUrl.cs | 18 ------------------ .../Utilities/TokenNotificationService.cs | 2 +- src/FrontOffice.Main/appsettings.Staging.json | 2 +- src/FrontOffice.Main/appsettings.json | 2 +- 6 files changed, 5 insertions(+), 28 deletions(-) delete mode 100644 src/FrontOffice.Main/Utilities/CmsServerBaseUrl.cs diff --git a/k8s/staging/frontoffice-deployment.yaml b/k8s/staging/frontoffice-deployment.yaml index bfcb1d1..989e9a2 100644 --- a/k8s/staging/frontoffice-deployment.yaml +++ b/k8s/staging/frontoffice-deployment.yaml @@ -1,6 +1,5 @@ --- -# FrontOffice (Blazor Server) — staging. Server-side gRPC/SignalR to CMS: set CmsInternalBaseUrl to the -# in-cluster Service URL so TLS is not terminated on a broken public chain (PartialChain). +# FrontOffice (Blazor Server) staging. apiVersion: apps/v1 kind: Deployment metadata: @@ -29,8 +28,6 @@ spec: env: - name: ASPNETCORE_ENVIRONMENT value: "Staging" - - name: CmsInternalBaseUrl - value: "http://cms-svc:8080" resources: requests: memory: "256Mi" diff --git a/src/FrontOffice.Main/ConfigureServices.cs b/src/FrontOffice.Main/ConfigureServices.cs index ca67e8c..d449a5a 100644 --- a/src/FrontOffice.Main/ConfigureServices.cs +++ b/src/FrontOffice.Main/ConfigureServices.cs @@ -100,9 +100,7 @@ public static class ConfigureServices public static IServiceCollection AddGrpcServices(this IServiceCollection services, IConfiguration configuration) { - var baseUrl = CmsServerBaseUrl.Resolve(configuration) - ?? throw new InvalidOperationException( - "GwUrl is required. Optionally set CmsInternalBaseUrl (e.g. http://cms-svc:8080 on Kubernetes) to bypass public TLS for server-side gRPC."); + var baseUrl = configuration["GwUrl"]; // Register optimized HttpClient for gRPC services.AddScoped(sp => diff --git a/src/FrontOffice.Main/Utilities/CmsServerBaseUrl.cs b/src/FrontOffice.Main/Utilities/CmsServerBaseUrl.cs deleted file mode 100644 index e7eb431..0000000 --- a/src/FrontOffice.Main/Utilities/CmsServerBaseUrl.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Microsoft.Extensions.Configuration; - -namespace FrontOffice.Main.Utilities; - -/// -/// Server-side base URL for CMS (gRPC-Web, SignalR). Prefer in-cluster HTTP when FrontOffice runs on Kubernetes -/// next to CMS to avoid public ingress TLS chain issues (e.g. PartialChain). -/// -public static class CmsServerBaseUrl -{ - public static string? Resolve(IConfiguration configuration) - { - var internalUrl = configuration["CmsInternalBaseUrl"]; - if (!string.IsNullOrWhiteSpace(internalUrl)) - return internalUrl.TrimEnd('/'); - return configuration["GwUrl"]?.TrimEnd('/'); - } -} diff --git a/src/FrontOffice.Main/Utilities/TokenNotificationService.cs b/src/FrontOffice.Main/Utilities/TokenNotificationService.cs index c4cd4f8..7912dc6 100644 --- a/src/FrontOffice.Main/Utilities/TokenNotificationService.cs +++ b/src/FrontOffice.Main/Utilities/TokenNotificationService.cs @@ -69,7 +69,7 @@ public class TokenNotificationService : IAsyncDisposable return; } - var gwUrl = CmsServerBaseUrl.Resolve(_configuration) ?? "https://localhost:5002"; + var gwUrl = _configuration["GwUrl"]?.TrimEnd('/') ?? "https://localhost:5002"; var hubPath = _configuration["SignalR:HubPath"] ?? "/hubs/token-relay"; var hubUrl = $"{gwUrl}{hubPath}"; diff --git a/src/FrontOffice.Main/appsettings.Staging.json b/src/FrontOffice.Main/appsettings.Staging.json index e9c8a09..e8763e2 100644 --- a/src/FrontOffice.Main/appsettings.Staging.json +++ b/src/FrontOffice.Main/appsettings.Staging.json @@ -1,5 +1,5 @@ { - "GwUrl": "https://cms.se.kbs1.ir", + "GwUrl": "http://cms-svc:8080", "DownloadUrl": "", "EncryptionSettings": { "Key": "kmcQ3XTmH4mrdh8VHziuscyf8LLYjG//Kyni81nH/0E=", diff --git a/src/FrontOffice.Main/appsettings.json b/src/FrontOffice.Main/appsettings.json index 6f287e6..92c3d39 100644 --- a/src/FrontOffice.Main/appsettings.json +++ b/src/FrontOffice.Main/appsettings.json @@ -1,5 +1,5 @@ { - "GwUrl": "https://localhost:32846", + "GwUrl": "https://cms.se.kbs1.ir", "DownloadUrl": "", "EncryptionSettings": { "Key": "kmcQ3XTmH4mrdh8VHziuscyf8LLYjG//Kyni81nH/0E=",