diff --git a/server.js b/server.js index 29b231c..28ce782 100644 --- a/server.js +++ b/server.js @@ -251,17 +251,33 @@ async function logActivity(type, message, ideaId = '', meta = '') { } app.get('/api/health', async (_req, res) => { - const health = { ok: false, app: 'rank', version: appVersion, appwriteConfigured: Boolean(endpoint && projectId && apiKey), appwriteReachable: false, tableReachable: false }; + const health = { + ok: false, + app: 'rank', + version: appVersion, + appwriteConfigured: Boolean(endpoint && projectId && apiKey), + appwriteReachable: false, + tableReachable: false, + tables: { ideas: false, milestones: false, activity: false }, + }; try { if (health.appwriteConfigured) { - const probe = await withTimeout( - tables.listRows({ databaseId, tableId: ideasTableId, queries: [Query.limit(1)] }), - 'Appwrite health probe' - ); - rowsFrom(probe); + const tableProbes = [ + ['ideas', ideasTableId], + ['milestones', milestonesTableId], + ['activity', activityTableId], + ]; + for (const [name, tableId] of tableProbes) { + const probe = await withTimeout( + tables.listRows({ databaseId, tableId, queries: [Query.limit(1)] }), + `Appwrite health probe (${name})` + ); + rowsFrom(probe); + health.tables[name] = true; + } health.appwriteReachable = true; - health.tableReachable = true; - health.ok = true; + health.tableReachable = Object.values(health.tables).every(Boolean); + health.ok = health.tableReachable; } } catch (error) { health.error = error.message;