Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/app/api/health/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { NextResponse } from 'next/server';
import { getServiceRoleClient } from '@/lib/supabase/service-role.js';

export const dynamic = 'force-dynamic';

const headers = { 'Cache-Control': 'no-store' };

/**
* Health check for status.profullstack.com: one cheap PostgREST HEAD query,
* capped at 3s. Never echoes the error, so nothing about the setup leaks.
*/
export async function GET() {
try {
const { error } = await getServiceRoleClient()
.from('users')
.select('id', { head: true })
.limit(1)
.abortSignal(AbortSignal.timeout(3000));
if (error) throw error;
return NextResponse.json({ status: 'ok', db: 'ok' }, { headers });
} catch {
return NextResponse.json({ status: 'error', db: 'down' }, { status: 503, headers });
}
}
3 changes: 3 additions & 0 deletions src/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export function middleware(request) {
return NextResponse.redirect(url, 301);
}

// Health checks (status.profullstack.com) are never rate limited.
if (pathname === '/api/health') return NextResponse.next();

const ip = getClientIp(request);

// Rate limiting
Expand Down
Loading