feat: implement issue #4 #5

Open
Luca wants to merge 1 commits from ai/issue-4 into master

50
public/api/health.php Normal file
View File

@@ -0,0 +1,50 @@
<?php
/**
* Health Check Endpoint
* Returns application health status and database connectivity
*/
header('Content-Type: application/json');
$health = [
'status' => 'ok',
'timestamp' => time()
];
// Check database connection
$dbConnected = false;
$dbError = null;
try {
$conn = @mysqli_connect(
'aide-mariadb',
'aide',
'aide',
'thetool_s13'
);
if ($conn) {
$dbConnected = true;
mysqli_close($conn);
}
} catch (Exception $e) {
$dbError = $e->getMessage();
}
if ($dbConnected) {
$health['db'] = true;
} else {
$health['db'] = false;
if ($dbError) {
$health['db_error'] = $dbError;
}
}
// Set HTTP status code
if ($health['db']) {
http_response_code(200);
} else {
http_response_code(503); // Service Unavailable
}
echo json_encode($health);