| 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 }, | |
| ); | |
| } | |
| } | |