From 0be8fc22b833cbb61e6ab5dcf91a2db06e048eaf Mon Sep 17 00:00:00 2001 From: Ryan Campbell <89273172+bigtallcampbell@users.noreply.github.com> Date: Fri, 2 Aug 2024 11:16:58 -0500 Subject: [PATCH] adjusting appsettings load (#19) --- src/Client.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Client.cs b/src/Client.cs index e6787cd..73d011c 100644 --- a/src/Client.cs +++ b/src/Client.cs @@ -121,14 +121,17 @@ public Client() { if (_grpcHost != null || _client != null) return; var builder = WebApplication.CreateBuilder(); + string _secretDir = Environment.GetEnvironmentVariable("SPACEFX_SECRET_DIR") ?? throw new Exception("SPACEFX_SECRET_DIR environment variable not set"); // Load the configuration being supplicated by the cluster first - builder.Configuration.AddJsonFile(Path.Combine("{env:SPACEFX_CONFIG_DIR}", "config", "appsettings.json"), optional: true, reloadOnChange: false); + builder.Configuration.AddJsonFile(Path.Combine($"{_secretDir}", "config", "appsettings.json"), optional: false, reloadOnChange: false); // Load any local appsettings incase they're overriding the cluster values builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json"), optional: true, reloadOnChange: false); // Load any local appsettings incase they're overriding the cluster values - builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.{env:DOTNET_ENVIRONMENT}.json"), optional: true, reloadOnChange: false); + string? dotnet_env = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT"); + if (!string.IsNullOrWhiteSpace(dotnet_env)) + builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), $"appsettings.{dotnet_env}.json"), optional: true, reloadOnChange: false); builder.WebHost.ConfigureKestrel(options => options.ListenAnyIP(50051, o => o.Protocols = HttpProtocols.Http2)) .ConfigureServices((services) => {