Ashgen12's picture
Recruitment Copilot
14fdc5e verified
Raw
History Blame Contribute Delete
867 Bytes
import { NextRequest } from "next/server";
export const runtime = "nodejs";
export async function POST(request: NextRequest) {
const backendBaseUrl = process.env.BACKEND_URL ?? "http://127.0.0.1:7860";
const body = await request.text();
const upstream = await fetch(`${backendBaseUrl}/api/chat`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body,
cache: "no-store"
});
if (!upstream.ok || !upstream.body) {
const text = await upstream.text();
return new Response(text || "Upstream chat request failed.", {
status: upstream.status || 500
});
}
return new Response(upstream.body, {
status: 200,
headers: {
"Content-Type": "text/event-stream",
"Cache-Control": "no-cache, no-transform",
Connection: "keep-alive"
}
});
}