fix: Blazor WASM 클라이언트 localhost:5265 하드코딩 전면 제거
Quant Engine CI/CD Pipeline / validate-core (push) Failing after 12s
WBS-9.3 - NULL Policy CI Gate / NULL Policy Validation (push) Failing after 8s
Quant Engine CI/CD Pipeline / validate-ui-and-storage (push) Has been skipped
Deploy to Production / Build & Deploy to Production (push) Successful in 2m40s

증상: 프로덕션에서 '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 호출.
This commit is contained in:
2026-07-06 17:48:34 +09:00
parent d5ede69800
commit 4e23a87085
3 changed files with 11 additions and 8 deletions
@@ -42,9 +42,10 @@ namespace QuantEngine.Web.Client.Infrastructure
try try
{ {
Console.WriteLine("[Auth] Attempting validation via /api/auth/me (cookie or Bearer)..."); Console.WriteLine("[Auth] Attempting validation via /api/auth/me (cookie or Bearer)...");
var baseUrl = _http.BaseAddress?.AbsoluteUri ?? "http://localhost:5265"; // BaseAddress is always set to HostEnvironment.BaseAddress by DI.
var meUrl = new Uri(new Uri(baseUrl), "api/auth/me").ToString(); // Never fall back to a hardcoded port — it breaks in production.
Console.WriteLine($"[Auth] /api/auth/me URL: {meUrl}"); var meUrl = "api/auth/me";
Console.WriteLine($"[Auth] /api/auth/me URL: {_http.BaseAddress}{meUrl}");
var meResponse = await _http.GetAsync(meUrl); var meResponse = await _http.GetAsync(meUrl);
Console.WriteLine($"[Auth] /api/auth/me status: {meResponse.StatusCode}"); Console.WriteLine($"[Auth] /api/auth/me status: {meResponse.StatusCode}");
@@ -136,10 +136,8 @@
{ {
try try
{ {
if (Http.BaseAddress == null) // BaseAddress is set to HostEnvironment.BaseAddress by DI in Client/Program.cs.
{ // Never override it with a hardcoded port.
Http.BaseAddress = new Uri("http://localhost:5265/");
}
var res = await Http.GetFromJsonAsync<List<UserDto>>("api/users"); var res = await Http.GetFromJsonAsync<List<UserDto>>("api/users");
if (res != null) if (res != null)
{ {
@@ -11,9 +11,13 @@ public class ApiClient
public ApiClient(HttpClient http, ILogger<ApiClient> logger) public ApiClient(HttpClient http, ILogger<ApiClient> logger)
{ {
_http = http; _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) 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; _logger = logger;
} }