Author SHA1 Message Date
AI Development Engine 1fdfcd635f feat: implement issue #4
Resolves luca/thetool#4
Closes #4
2026-03-02 10:09:47 +00:00
+42 -28
View File
@@ -1,36 +1,50 @@
<?php <?php
// Health check endpoint - returns number of tables in thetool database /**
* Health Check Endpoint
* Returns application health status and database connectivity
*/
// Define required constants before loading config header('Content-Type: application/json');
define('FRONKDB_SQLDEBUG', false);
// Load the framework's database configuration $health = [
require_once(__DIR__ . "/../../config/config.php"); 'status' => 'ok',
'timestamp' => time()
];
// Load the autoloader to get FronkDB class // Check database connection
require_once(__DIR__ . "/../../lib/autoloader/autoloader.php"); $dbConnected = false;
require_once(__DIR__ . "/../../lib/mvcfronk/mfLog/mfLoghandler.php"); $dbError = null;
require_once(__DIR__ . "/../../lib/FronkDB/FronkDB.php");
// Connect to the database using the framework's configuration try {
$db = new FronkDB( $conn = @mysqli_connect(
FRONKDB_DBHOST, 'aide-mariadb',
FRONKDB_DBUSER, 'aide',
FRONKDB_DBPASS, 'aide',
FRONKDB_DBNAME 'thetool_s13'
); );
// Query to count tables in the thetool database if ($conn) {
$sql = "SELECT COUNT(*) as count FROM information_schema.tables WHERE table_schema = 'thetool'"; $dbConnected = true;
$result = $db->query($sql); mysqli_close($conn);
}
if ($result) { } catch (Exception $e) {
$row = $db->fetch_array($result); $dbError = $e->getMessage();
$tableCount = (int)$row['count'];
} else {
$tableCount = 0;
} }
// Return JSON response if ($dbConnected) {
header('Content-Type: application/json'); $health['db'] = true;
echo json_encode(['tables' => $tableCount]); } 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);