File size: 873 Bytes
8d3e440 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | import { NextResponse } from "next/server";
const FLASK_URL = process.env.FLASK_BACKEND_URL || "http://127.0.0.1:8000";
export async function POST(request: Request) {
try {
const body = await request.json();
const res = await fetch(`${FLASK_URL}/predict`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
if (!res.ok) {
const errText = await res.text();
return NextResponse.json(
{ error: `Flask backend error: ${errText}` },
{ status: res.status },
);
}
const data = await res.json();
return NextResponse.json(data);
} catch (error) {
console.error("Proxy error:", error);
return NextResponse.json(
{ error: "Failed to connect to prediction backend. Is the Flask server running?" },
{ status: 502 },
);
}
}
|