24 lines
814 B
TypeScript
24 lines
814 B
TypeScript
|
|
// 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" },
|
||
|
|
});
|
||
|
|
}
|