47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { BE_BASE_URL } from "@/app/services/constants";
|
|
import { NextResponse } from "next/server";
|
|
|
|
// Proxy to backend metadata endpoint. Assumes BACKEND_BASE_URL is set.
|
|
export async function GET() {
|
|
const { cookies } = await import("next/headers");
|
|
const cookieStore = await cookies();
|
|
const token = cookieStore.get("auth_token")?.value;
|
|
|
|
if (!token) {
|
|
return NextResponse.json(
|
|
{ success: false, message: "No token found" },
|
|
{ status: 401 }
|
|
);
|
|
}
|
|
|
|
const url = `${BE_BASE_URL.replace(/\/$/, "")}/api/v1/metadata`;
|
|
|
|
try {
|
|
const res = await fetch(url, {
|
|
method: "GET",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
Authorization: `Bearer ${token}`,
|
|
},
|
|
cache: "no-store",
|
|
});
|
|
|
|
const data = await res.json();
|
|
|
|
if (!res.ok) {
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
message: data?.message || "Failed to fetch metadata",
|
|
},
|
|
{ status: res.status }
|
|
);
|
|
}
|
|
|
|
return NextResponse.json(data);
|
|
} catch (err) {
|
|
const message = (err as Error)?.message || "Metadata proxy error";
|
|
return NextResponse.json({ success: false, message }, { status: 500 });
|
|
}
|
|
}
|