co2 galvo owner test
This commit is contained in:
parent
2e08d68b24
commit
5257a0d2fe
3 changed files with 41 additions and 17 deletions
|
|
@ -1,23 +1,27 @@
|
|||
// app/api/dx/[...path]/route.ts
|
||||
import { NextResponse } from "next/server";
|
||||
import { dxGET } from "@/lib/directus";
|
||||
import { requireBearer } from "@/app/api/_lib/auth";
|
||||
|
||||
const BASE = (process.env.DIRECTUS_URL || "").replace(/\/$/, "");
|
||||
export const runtime = "nodejs";
|
||||
|
||||
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" },
|
||||
});
|
||||
// GET /api/dx/<anything...>?<query>
|
||||
// Proxies to Directus using the user's ma_at, no caching.
|
||||
export async function GET(
|
||||
req: Request,
|
||||
{ params }: { params: { path: string[] } }
|
||||
) {
|
||||
try {
|
||||
const bearer = requireBearer(req); // <-- pulls ma_at from Cookie
|
||||
const search = new URL(req.url).search; // keep original query
|
||||
const p = `/${(params.path || []).join("/")}${search || ""}`;
|
||||
const json = await dxGET<any>(p, bearer);
|
||||
return NextResponse.json(json, { status: 200 });
|
||||
} catch (e: any) {
|
||||
const status = e?.status ?? 500;
|
||||
return NextResponse.json(
|
||||
{ errors: [{ message: e?.message || "Directus proxy error", detail: e?.detail }] },
|
||||
{ status }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue