vector / frontend /src /app /api /feedback /route.ts
d-ragon's picture
Upload 674 files
689359a verified
Raw History Blame Contribute Delete
1.12 kB
import { headers } from "next/headers";
import { NextResponse } from "next/server";
import { auth } from "@/lib/auth";
import { buildBackendAuthHeaders } from "@/lib/backend-auth";
import { backendTraceHeaders } from "@/server/backend-api";
export async function POST(request: Request) {
const session = await auth.api.getSession({ headers: await headers() });
if (!session?.user?.id) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const payload = await request.text();
const apiUrl =
process.env.BACKEND_INTERNAL_URL ||
process.env.NEXT_PUBLIC_API_URL ||
"http://localhost:8000";
const upstream = await fetch(`${apiUrl}/feedback`, {
method: "POST",
headers: {
"Content-Type": "application/json",
...buildBackendAuthHeaders(session.user.id),
...(await backendTraceHeaders()),
},
body: payload,
});
const responseText = await upstream.text();
return new NextResponse(responseText, {
status: upstream.status,
headers: {
"Content-Type": upstream.headers.get("content-type") || "application/json",
},
});
}