34 lines
970 B
C#
34 lines
970 B
C#
using Heimdall.Infrastructure.Data;
|
|||
|
|
using Microsoft.AspNetCore.Authorization;
|
||
|
|
using Microsoft.AspNetCore.Mvc;
|
||
|
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
|
||
|
|
namespace Heimdall.Api.Controllers;
|
||
|
|
|
||
|
|
[ApiController]
|
||
|
|
[AllowAnonymous]
|
||
|
|
public class HealthController : ControllerBase
|
||
|
|
{
|
||
|
|
[HttpGet("/healthz")]
|
||
|
|
public IActionResult Health()
|
||
|
|
{
|
||
|
|
return Ok(new { status = "healthy", timestamp = DateTime.UtcNow });
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpGet("/readyz")]
|
||
|
|
public async Task<IActionResult> Readiness([FromServices] AppDbContext db)
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
var canConnect = await db.Database.CanConnectAsync();
|
||
|
|
if (!canConnect)
|
||
|
|
return StatusCode(503, new { status = "unhealthy", database = "disconnected" });
|
||
|
|
|
||
|
|
return Ok(new { status = "ready", database = "connected" });
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
return StatusCode(503, new { status = "unhealthy", database = ex.Message });
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|