35 lines
849 B
TypeScript
35 lines
849 B
TypeScript
import { NextResponse } from "next/server";
|
|
|
|
export const runtime = "nodejs";
|
|
export const maxDuration = 10;
|
|
|
|
export async function POST(request: Request) {
|
|
try {
|
|
const body = await request.json();
|
|
|
|
// 转发到 Florence-2 后端(本地服务)
|
|
const response = await fetch("http://localhost:8002/api/detect-object", {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(body),
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
return NextResponse.json(data);
|
|
} catch (error) {
|
|
console.error("Florence API proxy error:", error);
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
data: null,
|
|
error: `代理错误: ${error instanceof Error ? error.message : "未知错误"}`,
|
|
},
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|
|
|