From ceaf6de226226eb3419183ed928e9a7b50fd779c Mon Sep 17 00:00:00 2001 From: masoodafar-web Date: Thu, 14 May 2026 00:27:16 +0330 Subject: [PATCH] chore: enhance configuration for gateway URL handling - Added GW_URL and GwUrl environment variables in frontoffice-deployment.yaml and Dockerfile for consistent gateway URL configuration. - Updated AddGrpcServices method to resolve gateway URL from both environment variables, ensuring proper error handling for missing values. - Modified TokenNotificationService to prioritize GW_URL over GwUrl for improved configuration flexibility. --- k8s/staging/frontoffice-deployment.yaml | 4 ++++ src/FrontOffice.Main/ConfigureServices.cs | 12 +++++++++++- src/FrontOffice.Main/Dockerfile | 1 + .../Utilities/TokenNotificationService.cs | 2 +- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/k8s/staging/frontoffice-deployment.yaml b/k8s/staging/frontoffice-deployment.yaml index 989e9a2..88b5cf3 100644 --- a/k8s/staging/frontoffice-deployment.yaml +++ b/k8s/staging/frontoffice-deployment.yaml @@ -28,6 +28,10 @@ spec: env: - name: ASPNETCORE_ENVIRONMENT value: "Staging" + - name: GW_URL + value: "https://cms.se.kbs1.ir" + - name: GwUrl + value: "https://cms.se.kbs1.ir" resources: requests: memory: "256Mi" diff --git a/src/FrontOffice.Main/ConfigureServices.cs b/src/FrontOffice.Main/ConfigureServices.cs index d449a5a..e26f7b2 100644 --- a/src/FrontOffice.Main/ConfigureServices.cs +++ b/src/FrontOffice.Main/ConfigureServices.cs @@ -100,7 +100,8 @@ public static class ConfigureServices public static IServiceCollection AddGrpcServices(this IServiceCollection services, IConfiguration configuration) { - var baseUrl = configuration["GwUrl"]; + var baseUrl = ResolveGatewayUrl(configuration) + ?? throw new InvalidOperationException("Gateway URL is missing. Set GW_URL or GwUrl."); // Register optimized HttpClient for gRPC services.AddScoped(sp => @@ -152,6 +153,15 @@ public static class ConfigureServices return services; } + private static string? ResolveGatewayUrl(IConfiguration configuration) + { + var envUrl = configuration["GW_URL"]; + if (!string.IsNullOrWhiteSpace(envUrl)) + return envUrl.TrimEnd('/'); + + return configuration["GwUrl"]?.TrimEnd('/'); + } + private static TClient CreateAuthenticatedClient(IServiceProvider sp) where TClient : class { diff --git a/src/FrontOffice.Main/Dockerfile b/src/FrontOffice.Main/Dockerfile index 0320861..e6c235e 100644 --- a/src/FrontOffice.Main/Dockerfile +++ b/src/FrontOffice.Main/Dockerfile @@ -21,6 +21,7 @@ WORKDIR /app COPY --from=build /app/publish . ENV ASPNETCORE_URLS=http://+:80 +ENV GW_URL=https://cms.se.kbs1.ir EXPOSE 80 ENTRYPOINT ["dotnet", "FrontOffice.Main.dll"] diff --git a/src/FrontOffice.Main/Utilities/TokenNotificationService.cs b/src/FrontOffice.Main/Utilities/TokenNotificationService.cs index 7912dc6..b48609e 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 = _configuration["GwUrl"]?.TrimEnd('/') ?? "https://localhost:5002"; + var gwUrl = (_configuration["GW_URL"] ?? _configuration["GwUrl"])?.TrimEnd('/') ?? "https://localhost:5002"; var hubPath = _configuration["SignalR:HubPath"] ?? "/hubs/token-relay"; var hubUrl = $"{gwUrl}{hubPath}";