@page "/"
@using System.Net.Http.Headers
@using Spacebar.AdminAPI.TestClient.Services
@inject Config Config
@inject ILocalStorageService LocalStorage
Home
Spacebar API URL:
{
Config.ApiUrl = v!;
await ValidateAndSaveConfig();
})"/>
Spacebar CDN URL:
{
Config.CdnUrl = v!;
await ValidateAndSaveConfig();
})"/>
Spacebar Admin API URL:
{
Config.AdminUrl = v!;
await ValidateAndSaveConfig();
})"/>
Access Token:
{
Config.AccessToken = v!;
await ValidateAndSaveConfig();
})"/>
New access token
@code {
private bool IsApiUrlValid { get; set; }
// private bool IsGatewayUrlValid { get; set; }
private bool IsCdnUrlValid { get; set; }
private bool IsAdminApiUrlValid { get; set; }
private bool IsAccessTokenValid { get; set; }
protected override async Task OnInitializedAsync() {
await ValidateAndSaveConfig();
}
private async Task ValidateAndSaveConfig() {
await LocalStorage.SetItemAsync("sb_admin_tc_config", Config);
using var hc = new HttpClient();
HttpResponseMessage response;
try {
response = await hc.GetAsync(Config.ApiUrl + "/api/v9/policies/instance/domains");
IsApiUrlValid = response.IsSuccessStatusCode;
}
catch {
IsApiUrlValid = false;
}
StateHasChanged();
// response = await hc.GetAsync(Config.GatewayUrl + "/api/v9/policies/instance");
// IsGatewayUrlValid = response.IsSuccessStatusCode;
// StateHasChanged();
try {
response = await hc.GetAsync(Config.CdnUrl + "/ping");
IsCdnUrlValid = response.IsSuccessStatusCode;
}
catch {
IsCdnUrlValid = false;
}
StateHasChanged();
try {
response = await hc.GetAsync(Config.AdminUrl + "/_spacebar/admin/ping");
IsAdminApiUrlValid = response.IsSuccessStatusCode;
}
catch {
IsAdminApiUrlValid = false;
}
StateHasChanged();
try {
var request = new HttpRequestMessage(HttpMethod.Get, Config.AdminUrl + "/_spacebar/admin/whoami");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Config.AccessToken);
response = await hc.SendAsync(request);
IsAccessTokenValid = response.IsSuccessStatusCode;
}
catch {
IsAccessTokenValid = false;
}
StateHasChanged();
}
}