Fix deployed data rendering and database fallback

This commit is contained in:
2026-06-11 15:09:54 +07:00
parent b3d680cf66
commit 200918b725
3 changed files with 72 additions and 8 deletions
+12
View File
@@ -28,6 +28,7 @@ $action = $segments[2] ?? null;
// Coba koneksi DB — jika gagal, pakai demo mode
$dbOk = false;
$dbError = '';
try {
require_once __DIR__ . '/../config/database.php';
$testDb = getDB();
@@ -37,10 +38,21 @@ try {
} catch (Throwable $e) {
// DB tidak tersedia — pakai demo mode
$dbOk = false;
$dbError = $e->getMessage();
}
// ── DEMO MODE (tanpa database) ──────────────────────────────
if (!$dbOk) {
if (!in_array($method, ['GET', 'OPTIONS'], true)) {
http_response_code(503);
echo json_encode([
'success' => false,
'message' => 'Database belum siap, data tidak bisa disimpan. Periksa DB_HOST, DB_USER, DB_PASSWORD, dan schema webgis_kemiskinan.',
'errors' => ['database' => $dbError],
], JSON_UNESCAPED_UNICODE);
exit;
}
demoRouter($resource, $id, $action, $method);
exit;
}