The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
import * as Sentry from '@sentry/nextjs'
import { supabaseSearchV2 } from '~/scripts/search_v2/client'
import { type NextRequest } from 'next/server'
import { corsHeaders } from './cors'
export const runtime = 'edge'
export async function OPTIONS() {
return new Response(null, { headers: corsHeaders })
}
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url)
const query = searchParams.get('q')?.trim()
const limit = Number(searchParams.get('limit')) || 10
if (!query) {
return Response.json({ error: 'Missing q parameter' }, { status: 400, headers: corsHeaders })
}
const { data, error } = await supabaseSearchV2().rpc('search_docs', {
query_text: query,
match_limit: limit,
})
if (error) {
console.error('Error running docs search v2:', error)
Sentry.captureException(new Error(error.message), {
tags: { route: 'search_v2' },
extra: { query, limit, error },
})
return Response.json({ error: error.message }, { status: 500, headers: corsHeaders })
}
return Response.json(data, { headers: corsHeaders })
} catch (error) {
console.error('Error handling docs search v2 request:', error)
Sentry.captureException(error, { tags: { route: 'search_v2' } })
return Response.json(
{ error: 'There was an error processing your request' },
{ status: 500, headers: corsHeaders }
)
}
}