Try manually crafting request urls to fix deploy-only bug.

This commit is contained in:
2024-02-10 21:02:48 -06:00
parent 98d28d5b91
commit ffdeabe54a

View File

@@ -16,13 +16,16 @@ namespace Shogi.UI.Pages.Home.Api
private readonly AccountState accountState;
private readonly HttpClient guestHttpClient;
private readonly HttpClient msalHttpClient;
private readonly string baseUrl;
public ShogiApi(IHttpClientFactory clientFactory, AccountState accountState)
public ShogiApi(IHttpClientFactory clientFactory, AccountState accountState, IConfiguration configuration)
{
this.serializerOptions = new JsonSerializerOptions(JsonSerializerDefaults.Web);
this.accountState = accountState;
this.guestHttpClient = clientFactory.CreateClient(GuestClientName);
this.msalHttpClient = clientFactory.CreateClient(MsalClientName);
this.baseUrl = configuration["ShogiApiUrl"] ?? throw new InvalidOperationException("Configuration missing.");
this.baseUrl = this.baseUrl.TrimEnd('/');
}
private HttpClient HttpClient => accountState.User?.WhichAccountPlatform switch
@@ -40,7 +43,7 @@ namespace Shogi.UI.Pages.Home.Api
public async Task<Session?> GetSession(string name)
{
var response = await HttpClient.GetAsync(new Uri($"Sessions/{name}", UriKind.Relative));
var response = await HttpClient.GetAsync(RelativeUri($"Sessions/{name}"));
if (response.IsSuccessStatusCode)
{
return (await response.Content.ReadFromJsonAsync<ReadSessionResponse>(serializerOptions))?.Session;
@@ -98,6 +101,6 @@ namespace Shogi.UI.Pages.Home.Api
return HttpClient.PatchAsync(RelativeUri($"Sessions/{name}/Join"), null);
}
private static Uri RelativeUri(string path) => new(path, UriKind.Relative);
private Uri RelativeUri(string path) => new($"{this.baseUrl}/{path}", UriKind.Absolute);
}
}