File size: 1,033 Bytes
689359a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | import { NextResponse } from "next/server";
import { createTextProxyResponse, fetchBackend } from "@/server/backend-api";
import { getServerSession } from "@/server/session";
export async function GET() {
const session = await getServerSession();
if (!session?.user?.id) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const upstream = await fetchBackend("/api-keys/", {
method: "GET",
userId: session.user.id,
cache: "no-store",
});
return createTextProxyResponse(upstream);
}
export async function POST(request: Request) {
const session = await getServerSession();
if (!session?.user?.id) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const body = await request.text();
const upstream = await fetchBackend("/api-keys/", {
method: "POST",
userId: session.user.id,
extraHeaders: { "Content-Type": "application/json" },
body: body || "{}",
cache: "no-store",
});
return createTextProxyResponse(upstream);
}
|