1 Commits

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

View File

@@ -1,36 +1,50 @@
<?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
define('FRONKDB_SQLDEBUG', false);
header('Content-Type: application/json');
// Load the framework's database configuration
require_once(__DIR__ . "/../../config/config.php");
$health = [
'status' => 'ok',
'timestamp' => time()
];
// Load the autoloader to get FronkDB class
require_once(__DIR__ . "/../../lib/autoloader/autoloader.php");
require_once(__DIR__ . "/../../lib/mvcfronk/mfLog/mfLoghandler.php");
require_once(__DIR__ . "/../../lib/FronkDB/FronkDB.php");
// Check database connection
$dbConnected = false;
$dbError = null;
// Connect to the database using the framework's configuration
$db = new FronkDB(
FRONKDB_DBHOST,
FRONKDB_DBUSER,
FRONKDB_DBPASS,
FRONKDB_DBNAME
);
try {
$conn = @mysqli_connect(
'aide-mariadb',
'aide',
'aide',
'thetool_s13'
);
// Query to count tables in the thetool database
$sql = "SELECT COUNT(*) as count FROM information_schema.tables WHERE table_schema = 'thetool'";
$result = $db->query($sql);
if ($result) {
$row = $db->fetch_array($result);
$tableCount = (int)$row['count'];
} else {
$tableCount = 0;
if ($conn) {
$dbConnected = true;
mysqli_close($conn);
}
} catch (Exception $e) {
$dbError = $e->getMessage();
}
// Return JSON response
header('Content-Type: application/json');
echo json_encode(['tables' => $tableCount]);
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);