makearmy-app/app/api/dx/[...path]/route.ts

24 lines
814 B
TypeScript
Raw Normal View History

2025-10-01 20:57:05 -04:00
// app/api/dx/[...path]/route.ts
import { NextResponse } from "next/server";
import { requireBearer } from "@/app/api/_lib/auth";
const BASE = (process.env.DIRECTUS_URL || "").replace(/\/$/, "");
export async function GET(req: Request, { params }: { params: { path: string[] } }) {
const bearer = requireBearer(req);
const search = new URL(req.url).search || "";
const path = params.path.join("/");
const url = `${BASE}/${path}${search}`;
const res = await fetch(url, {
headers: { Accept: "application/json", Authorization: `Bearer ${bearer}` },
cache: "no-store",
});
const body = await res.text();
return new NextResponse(body, {
status: res.status,
headers: { "content-type": res.headers.get("content-type") || "application/json" },
});
}