Reputation: 23224
I want Program.Main
in my Blazor WebAssembly app to make a call to the server that served the app before booting up the app - so I can grab some configuration settings from the server.
Is there a way to determine what the server URL was?
Upvotes: 1
Views: 501
Reputation: 23224
Looks like I can make a server request in Program.Main
like this
private static Task<ClientConfiguration> GetClientConfigurationAsync()
{
var serviceProvider = new ServiceCollection()
.AddBaseAddressHttpClient()
.BuildServiceProvider();
var httpClient = serviceProvider.GetRequiredService<HttpClient>();
return httpClient.GetJsonAsync<ClientConfiguration>("api/client-configuration");
}
Upvotes: 2