2021-10-10 17:30:31 +08:00
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Net;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
2021-10-12 16:52:28 +08:00
|
|
|
|
namespace Yi.Framework.WebCore.MiddlewareExtend
|
2021-10-10 17:30:31 +08:00
|
|
|
|
{
|
2021-10-12 16:52:28 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 健康检测扩展
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static class HealthCheckExtension
|
2021-10-10 17:30:31 +08:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设置心跳响应
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="app"></param>
|
|
|
|
|
|
/// <param name="checkPath">默认是/Health</param>
|
|
|
|
|
|
/// <returns></returns>
|
2022-04-12 22:12:11 +08:00
|
|
|
|
public static void UseHealthCheckService(this IApplicationBuilder app, string checkPath = "/Health")
|
2021-10-10 17:30:31 +08:00
|
|
|
|
{
|
2021-10-26 15:09:07 +08:00
|
|
|
|
if (Appsettings.appBool("HealthCheck_Enabled"))
|
2021-10-10 17:30:31 +08:00
|
|
|
|
{
|
2021-10-26 15:09:07 +08:00
|
|
|
|
app.Map(checkPath, applicationBuilder => applicationBuilder.Run(async context =>
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine($"This is Health Check");
|
|
|
|
|
|
context.Response.StatusCode = (int)HttpStatusCode.OK;
|
|
|
|
|
|
await context.Response.WriteAsync("OK");
|
|
|
|
|
|
}));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-10-10 17:30:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|