Inject framework HttpClient to support prerendering behavior on server instead of baking in the HttpClient on the client project
This commit is contained in:
@@ -16,6 +16,32 @@ public static class Startup
|
||||
// Add Track services
|
||||
builder.Services.AddScoped<TrackRepository>();
|
||||
builder.Services.AddScoped<TrackService>();
|
||||
}
|
||||
|
||||
public static string GetKestrelUrl(this WebApplicationBuilder builder)
|
||||
{
|
||||
// Check all the places Kestrel URL can be configured
|
||||
var urls = builder.Configuration["ASPNETCORE_URLS"]
|
||||
?? builder.Configuration["urls"];
|
||||
|
||||
if (!string.IsNullOrEmpty(urls))
|
||||
{
|
||||
return urls.Split(';')[0].Trim();
|
||||
}
|
||||
|
||||
// Check Kestrel endpoints configuration
|
||||
var kestrelSection = builder.Configuration.GetSection("Kestrel:Endpoints");
|
||||
var firstEndpoint = kestrelSection.GetChildren().FirstOrDefault();
|
||||
var endpointUrl = firstEndpoint?["Url"];
|
||||
|
||||
if (!string.IsNullOrEmpty(endpointUrl))
|
||||
{
|
||||
return endpointUrl;
|
||||
}
|
||||
|
||||
// ASP.NET Core defaults
|
||||
return builder.Environment.IsDevelopment()
|
||||
? "https://localhost:5001"
|
||||
: "http://localhost:5000";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user