Files

19 lines
994 B
TypeScript

import { NextResponse, type NextRequest } from "next/server";
import { callMobileApi } from "@/app/lib/server/mobileApi";
import { getToken } from "@/app/lib/server/session";
import { badRequest, errorResponse, unauthorized } from "@/app/lib/server/apiRoute";
// Read-only proxy for /api/admin/emails; mobile-api owns the BO_EMAILS and super-admin guards.
type Ctx = { params: Promise<{ path?: string[] }> };
export async function GET(req: NextRequest, { params }: Ctx) {
const token = await getToken();
if (!token) return unauthorized();
const { path = [] } = await params; // [[...path]]: the list call has no segment
if (path.some((s) => s === "." || s === "..")) return badRequest("Invalid path.");
const target = `/api/admin/emails${path.map(encodeURIComponent).map((s) => `/${s}`).join("")}${new URL(req.url).search}`;
const result = await callMobileApi<unknown>(target, { token });
if (!result.ok) return errorResponse(result);
return NextResponse.json(result.data);
}