コード例 #1
0
        public static void UseHealthCheck(this IApplicationBuilder app, string path = "/health")
        {
            app.Map(path, s =>
            {
                s.Run(async context =>
                {
                    HealthCheckRegistry.HealthStatus status = await Task.Run(() => HealthCheckRegistry.GetStatus());

                    if (!status.IsHealthy)
                    {
                        // Return a service unavailable status code if any of the checks fail
                        context.Response.StatusCode = 503;
                    }
                    context.Response.ContentType = DEFAULT_CONTENT_TYPE;
                    await context.Response.WriteAsync(JsonConvert.SerializeObject(status));
                });
            });
        }
コード例 #2
0
        public static void UseHealthCheck(this IApplicationBuilder app, string path = "/health")
        {
            app.Map(path, s =>
            {
                s.Run(async context =>
                {
                    var remoteIp = context.Connection.RemoteIpAddress;
                    if (!IPAddress.IsLoopback(remoteIp))
                    {
                        context.Response.StatusCode  = 403;
                        context.Response.ContentType = "application/html";
                        await context.Response.WriteAsync("<font size=\"7\">403</font><br/>");
                    }
                    else
                    {
                        HealthCheckRegistry.HealthStatus status = await Task.Run(() => HealthCheckRegistry.GetStatus());

                        if (!status.IsHealthy)
                        {
                            // Return a service unavailable status code if any of the checks fail
                            context.Response.StatusCode = 503;
                        }
                        context.Response.ContentType = DEFAULT_CONTENT_TYPE;
                        await context.Response.WriteAsync(JsonConvert.SerializeObject(status));
                    }
                });
            });
        }