From 4e23a87085ce6541d84a4510797002b62451a44e Mon Sep 17 00:00:00 2001 From: kjh2064 Date: Mon, 6 Jul 2026 17:48:34 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20Blazor=20WASM=20=ED=81=B4=EB=9D=BC?= =?UTF-8?q?=EC=9D=B4=EC=96=B8=ED=8A=B8=20localhost:5265=20=ED=95=98?= =?UTF-8?q?=EB=93=9C=EC=BD=94=EB=94=A9=20=EC=A0=84=EB=A9=B4=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 증상: 프로덕션에서 'Connection refused (localhost:5265)' 오류 원인: WASM 클라이언트 3개 파일에 localhost:5265 null-fallback이 박혀 있어 브라우저가 사용자 로컬 포트로 API 요청을 시도함. 수정 파일: - ApiClient.cs: null fallback 제거 → 잘못된 DI 구성 시 명시적 예외 발생 - Users.razor: LoadUsers()의 BaseAddress 강제 설정 제거 - CustomAuthenticationStateProvider.cs: baseUrl fallback 제거, 상대 경로 사용 올바른 동작: Client/Program.cs에서 builder.HostEnvironment.BaseAddress로 DI 등록 → 항상 현재 도메인 기준 상대 경로로 API 호출. --- .../Infrastructure/CustomAuthenticationStateProvider.cs | 7 ++++--- src/dotnet/QuantEngine.Web/Client/Pages/Users.razor | 6 ++---- src/dotnet/QuantEngine.Web/Client/Services/ApiClient.cs | 6 +++++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/dotnet/QuantEngine.Web/Client/Infrastructure/CustomAuthenticationStateProvider.cs b/src/dotnet/QuantEngine.Web/Client/Infrastructure/CustomAuthenticationStateProvider.cs index c11f468..772c040 100644 --- a/src/dotnet/QuantEngine.Web/Client/Infrastructure/CustomAuthenticationStateProvider.cs +++ b/src/dotnet/QuantEngine.Web/Client/Infrastructure/CustomAuthenticationStateProvider.cs @@ -42,9 +42,10 @@ namespace QuantEngine.Web.Client.Infrastructure try { Console.WriteLine("[Auth] Attempting validation via /api/auth/me (cookie or Bearer)..."); - var baseUrl = _http.BaseAddress?.AbsoluteUri ?? "http://localhost:5265"; - var meUrl = new Uri(new Uri(baseUrl), "api/auth/me").ToString(); - Console.WriteLine($"[Auth] /api/auth/me URL: {meUrl}"); + // BaseAddress is always set to HostEnvironment.BaseAddress by DI. + // Never fall back to a hardcoded port — it breaks in production. + var meUrl = "api/auth/me"; + Console.WriteLine($"[Auth] /api/auth/me URL: {_http.BaseAddress}{meUrl}"); var meResponse = await _http.GetAsync(meUrl); Console.WriteLine($"[Auth] /api/auth/me status: {meResponse.StatusCode}"); diff --git a/src/dotnet/QuantEngine.Web/Client/Pages/Users.razor b/src/dotnet/QuantEngine.Web/Client/Pages/Users.razor index e5b9d98..c4fec35 100644 --- a/src/dotnet/QuantEngine.Web/Client/Pages/Users.razor +++ b/src/dotnet/QuantEngine.Web/Client/Pages/Users.razor @@ -136,10 +136,8 @@ { try { - if (Http.BaseAddress == null) - { - Http.BaseAddress = new Uri("http://localhost:5265/"); - } + // BaseAddress is set to HostEnvironment.BaseAddress by DI in Client/Program.cs. + // Never override it with a hardcoded port. var res = await Http.GetFromJsonAsync>("api/users"); if (res != null) { diff --git a/src/dotnet/QuantEngine.Web/Client/Services/ApiClient.cs b/src/dotnet/QuantEngine.Web/Client/Services/ApiClient.cs index 18bb856..d6753c9 100644 --- a/src/dotnet/QuantEngine.Web/Client/Services/ApiClient.cs +++ b/src/dotnet/QuantEngine.Web/Client/Services/ApiClient.cs @@ -11,9 +11,13 @@ public class ApiClient public ApiClient(HttpClient http, ILogger logger) { _http = http; + // BaseAddress is set by the DI registration in Client/Program.cs via + // builder.HostEnvironment.BaseAddress — never hardcode a port here. if (_http.BaseAddress == null) { - _http.BaseAddress = new Uri("http://localhost:5265/"); + throw new InvalidOperationException( + "ApiClient: HttpClient.BaseAddress is null. " + + "Ensure the HttpClient is registered with HostEnvironment.BaseAddress in Client/Program.cs."); } _logger = logger; }