clinicpal / src /app /api /rag /retrieve /route.ts
Vrda's picture
Deploy ClinIcPal frontend
9bc2f29 verified
import { NextResponse } from 'next/server';
const RAG_BACKEND_URL = process.env.RAG_BACKEND_URL || 'http://localhost:8000';
// POST /api/rag/retrieve — Proxy to RAG backend /v1/retrieve
export async function POST(request: Request) {
try {
const body = await request.json();
const res = await fetch(`${RAG_BACKEND_URL}/v1/retrieve`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
signal: AbortSignal.timeout(30000),
});
if (!res.ok) {
const err = await res.json().catch(() => ({ detail: res.statusText }));
return NextResponse.json(
{ success: false, error: err.detail || 'Retrieve failed' },
{ status: res.status }
);
}
const data = await res.json();
return NextResponse.json({ success: true, data });
} catch (error) {
return NextResponse.json(
{
success: false,
error: error instanceof Error ? error.message : 'Internal error',
},
{ status: 500 }
);
}
}