From 2c70ba45d4ce2689671ecba85e05b1ad5c9ca486 Mon Sep 17 00:00:00 2001 From: Beau Findlay Date: Tue, 12 Mar 2024 20:46:48 +0000 Subject: [PATCH] Use local host API base if in dev env --- BeauFindlay/src/BeauFindlay.Client/Program.cs | 12 ++++++++++-- .../src/BeauFindlay.Client/wwwroot/index.html | 1 - 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/BeauFindlay/src/BeauFindlay.Client/Program.cs b/BeauFindlay/src/BeauFindlay.Client/Program.cs index 35091e5..8dcd37c 100644 --- a/BeauFindlay/src/BeauFindlay.Client/Program.cs +++ b/BeauFindlay/src/BeauFindlay.Client/Program.cs @@ -7,10 +7,18 @@ var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add("#app"); builder.RootComponents.Add("head::after"); -var apiBase = builder.Configuration["ApiBase"] +string apiBase; +if (builder.HostEnvironment.IsDevelopment()) +{ + apiBase = builder.Configuration["ApiBase"] ?? throw new ArgumentException("API base address not found in config."); +} +else +{ + apiBase = builder.HostEnvironment.BaseAddress; +} -builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(apiBase) }); builder.Services.AddSingleton(); diff --git a/BeauFindlay/src/BeauFindlay.Client/wwwroot/index.html b/BeauFindlay/src/BeauFindlay.Client/wwwroot/index.html index 4b260d3..92a81b4 100644 --- a/BeauFindlay/src/BeauFindlay.Client/wwwroot/index.html +++ b/BeauFindlay/src/BeauFindlay.Client/wwwroot/index.html @@ -26,7 +26,6 @@ -