import { NextResponse } from 'next/server'; const DB_URL = (process.env.PHP_DB_URL ?? 'http://localhost:8080/DB4js_all.php') .replace(/\?.*$/, ''); async function proxy(req: Request) { const search = new URL(req.url).search; const target = DB_URL + search; const isReadOnly = req.method === 'GET' || req.method === 'HEAD'; const upstream = await fetch(target, { method: req.method, headers: { 'content-type': req.headers.get('content-type') ?? 'application/x-www-form-urlencoded' }, body: isReadOnly ? undefined : await req.arrayBuffer(), cache: 'no-store', }); const body = await upstream.arrayBuffer(); return new NextResponse(Buffer.from(body), { status: upstream.status, headers: { 'content-type': upstream.headers.get('content-type') ?? 'application/json' }, }); } export const GET = proxy; export const POST = proxy;