Specific health checks implementations registered into the application (#619)
This commit is contained in:
@@ -1,31 +1,25 @@
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using BlazorShared;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
|
||||
namespace Microsoft.eShopWeb.Web.HealthChecks;
|
||||
|
||||
public class ApiHealthCheck : IHealthCheck
|
||||
{
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly LinkGenerator _linkGenerator;
|
||||
private readonly BaseUrlConfiguration _baseUrlConfiguration;
|
||||
|
||||
public ApiHealthCheck(IHttpContextAccessor httpContextAccessor, LinkGenerator linkGenerator)
|
||||
public ApiHealthCheck(BaseUrlConfiguration baseUrlConfiguration)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_linkGenerator = linkGenerator;
|
||||
_baseUrlConfiguration = baseUrlConfiguration;
|
||||
}
|
||||
|
||||
public async Task<HealthCheckResult> CheckHealthAsync(
|
||||
HealthCheckContext context,
|
||||
CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
var request = _httpContextAccessor.HttpContext.Request;
|
||||
|
||||
string apiLink = _linkGenerator.GetPathByAction("List", "Catalog");
|
||||
string myUrl = request.Scheme + "://" + request.Host.ToString() + apiLink;
|
||||
string myUrl = _baseUrlConfiguration.ApiBase + "catalog-items";
|
||||
var client = new HttpClient();
|
||||
var response = await client.GetAsync(myUrl);
|
||||
var pageContents = await response.Content.ReadAsStringAsync();
|
||||
|
||||
Reference in New Issue
Block a user