feat: add sales-first Rank landing
This commit is contained in:
@@ -16,6 +16,15 @@ const milestonesTableId = process.env.RANK_MILESTONES_TABLE_ID || 'milestones';
|
||||
const activityTableId = process.env.RANK_ACTIVITY_TABLE_ID || 'activity';
|
||||
const agentToken = process.env.RANK_AGENT_TOKEN || process.env.PRIORITY_AGENT_TOKEN || '';
|
||||
const appVersion = process.env.APP_VERSION || 'rank-local';
|
||||
const appwriteTimeoutMs = Number(process.env.APPWRITE_TIMEOUT_MS || 7000);
|
||||
|
||||
function withTimeout(promise, label = 'operation') {
|
||||
let timer;
|
||||
const timeout = new Promise((_, reject) => {
|
||||
timer = setTimeout(() => reject(new Error(`${label} timed out after ${appwriteTimeoutMs}ms`)), appwriteTimeoutMs);
|
||||
});
|
||||
return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
|
||||
}
|
||||
|
||||
if (!endpoint || !projectId || !apiKey) {
|
||||
console.warn('[rank] Missing Appwrite configuration; /api/health will report degraded.');
|
||||
@@ -169,7 +178,10 @@ app.get('/api/health', async (_req, res) => {
|
||||
const health = { ok: false, app: 'rank', version: appVersion, appwriteConfigured: Boolean(endpoint && projectId && apiKey), appwriteReachable: false, tableReachable: false };
|
||||
try {
|
||||
if (health.appwriteConfigured) {
|
||||
const probe = await tables.listRows({ databaseId, tableId: ideasTableId, queries: [Query.limit(1)] });
|
||||
const probe = await withTimeout(
|
||||
tables.listRows({ databaseId, tableId: ideasTableId, queries: [Query.limit(1)] }),
|
||||
'Appwrite health probe'
|
||||
);
|
||||
rowsFrom(probe);
|
||||
health.appwriteReachable = true;
|
||||
health.tableReachable = true;
|
||||
@@ -182,11 +194,11 @@ app.get('/api/health', async (_req, res) => {
|
||||
});
|
||||
|
||||
app.get('/api/bootstrap', async (_req, res) => {
|
||||
const [ideas, milestones, activity] = await Promise.all([
|
||||
const [ideas, milestones, activity] = await withTimeout(Promise.all([
|
||||
tables.listRows({ databaseId, tableId: ideasTableId, queries: [Query.equal('archived', false), Query.orderDesc('score'), Query.orderAsc('rank'), Query.limit(100)] }),
|
||||
tables.listRows({ databaseId, tableId: milestonesTableId, queries: [Query.equal('active', true), Query.orderAsc('position'), Query.limit(50)] }),
|
||||
tables.listRows({ databaseId, tableId: activityTableId, queries: [Query.orderDesc('$createdAt'), Query.limit(18)] }).catch(() => ({ rows: [], documents: [] })),
|
||||
]);
|
||||
]), 'Appwrite bootstrap');
|
||||
res.json({
|
||||
version: appVersion,
|
||||
ideas: rowsFrom(ideas).map(publicIdea),
|
||||
|
||||
Reference in New Issue
Block a user