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
42 changes: 42 additions & 0 deletions app/api/cron/supabase-keepalive/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'server-only'
import { NextRequest, NextResponse } from 'next/server'
import { createAdminClient } from '@/lib/database/supabase-admin'

export async function GET(request: NextRequest) {
const cronSecret = process.env.CRON_SECRET
const authorization = request.headers.get('authorization')

if (!cronSecret || authorization !== `Bearer ${cronSecret}`) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}

const supabase = createAdminClient()

if (!supabase) {
return NextResponse.json(
{ error: 'Supabase service role is not configured' },
{ status: 500 }
)
}

const startedAt = Date.now()
const { error, count } = await supabase
.from('profiles')
.select('id', { count: 'exact', head: true })
.limit(1)

if (error) {
console.error('Supabase keepalive failed:', error.message)
return NextResponse.json(
{ error: 'Supabase keepalive failed' },
{ status: 502 }
)
}

return NextResponse.json({
ok: true,
checked: 'profiles',
count,
latencyMs: Date.now() - startedAt,
})
}
8 changes: 8 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"crons": [
{
"path": "/api/cron/supabase-keepalive",
"schedule": "0 3 * * *"
}
]
}
Loading