ClauseGuard / web /app /api /redline /route.ts
gaurv007's picture
v4.0: Add web /api/redline route for clause redlining
e484722 verified
raw
history blame
1.1 kB
import { NextRequest, NextResponse } from "next/server";
const API_URL = process.env.CLAUSEGUARD_API_URL || "https://gaurv007-clauseguard-api.hf.space";
export async function POST(req: NextRequest) {
try {
const body = await req.json();
const { session_id, text, use_llm } = body;
if (!session_id && !text) {
return NextResponse.json(
{ error: "Provide session_id or text" },
{ status: 400 }
);
}
const response = await fetch(`${API_URL}/api/redline`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ session_id, text, use_llm: use_llm ?? true }),
});
if (!response.ok) {
const err = await response.text().catch(() => "");
throw new Error(err || `Backend error: ${response.status}`);
}
const result = await response.json();
return NextResponse.json(result);
} catch (error: any) {
console.error("Redline error:", error.message);
return NextResponse.json(
{ error: error.message || "Redlining failed" },
{ status: 500 }
);
}
}