Spaces:
Sleeping
Sleeping
Upload web/app/api/compare/route.ts
Browse files- web/app/api/compare/route.ts +33 -0
web/app/api/compare/route.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
+
|
| 3 |
+
const API_URL = process.env.CLAUSEGUARD_API_URL || "https://gaurv007-clauseguard-api.hf.space";
|
| 4 |
+
|
| 5 |
+
export async function POST(req: NextRequest) {
|
| 6 |
+
try {
|
| 7 |
+
const body = await req.json();
|
| 8 |
+
const { text_a, text_b } = body;
|
| 9 |
+
|
| 10 |
+
if (!text_a || !text_b || text_a.trim().length < 50 || text_b.trim().length < 50) {
|
| 11 |
+
return NextResponse.json(
|
| 12 |
+
{ error: "Both contracts must have at least 50 characters." },
|
| 13 |
+
{ status: 400 }
|
| 14 |
+
);
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
const response = await fetch(`${API_URL}/api/compare`, {
|
| 18 |
+
method: "POST",
|
| 19 |
+
headers: { "Content-Type": "application/json" },
|
| 20 |
+
body: JSON.stringify({ text_a, text_b }),
|
| 21 |
+
});
|
| 22 |
+
|
| 23 |
+
if (!response.ok) {
|
| 24 |
+
throw new Error(`Backend error: ${response.status}`);
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
const result = await response.json();
|
| 28 |
+
return NextResponse.json(result);
|
| 29 |
+
} catch (error: any) {
|
| 30 |
+
console.error("Compare error:", error.message);
|
| 31 |
+
return NextResponse.json({ error: error.message || "Comparison failed" }, { status: 500 });
|
| 32 |
+
}
|
| 33 |
+
}
|