diverse änderungen

This commit is contained in:
marco committed 2026-11-05 15:17:01 +01:00
1 parent 0e7b53e558
commit 54d5e58798
60 files changed
+1637 -122

No files matched your search

@@ -0,0 +1,37 @@
import { NextRequest } from 'next/server';
export const runtime = 'nodejs';
export const dynamic = 'force-dynamic';
type Context = { params: Promise<{ id: string; path?: string[] }> };
async function proxy(request: NextRequest, context: Context) {
const { id, path = [] } = await context.params;
if (!/^[a-f\d]{24}$/i.test(id) || !(
path.length === 0 || path.length === 1 && ['file', 'units'].includes(path[0]) ||
path.length === 2 && path[0] === 'units' && /^[a-f\d]{24}$/i.test(path[1])
)) return Response.json({ message: 'Ungültiger PDF-Pfad' }, { status: 400 });
const url = new URL(`http://localhost:3000/anlage/${id}/pdf${path.length ? '/' + path.join('/') : ''}`);
url.search = request.nextUrl.search;
const headers = new Headers();
for (const name of ['content-type', 'range', 'if-range']) {
const value = request.headers.get(name);
if (value) headers.set(name, value);
}
try {
const response = await fetch(url, {
method: request.method, headers, cache: 'no-store',
body: request.method === 'GET' ? undefined : await request.arrayBuffer(),
});
const outgoing = new Headers({ 'Cache-Control': 'no-store' });
for (const name of ['content-type', 'content-length', 'content-range', 'accept-ranges']) {
const value = response.headers.get(name);
if (value) outgoing.set(name, value);
}
return new Response(response.body, { status: response.status, headers: outgoing });
} catch {
return Response.json({ message: 'Keine Verbindung zum Backend' }, { status: 502 });
}
}
export { proxy as GET, proxy as POST, proxy as PATCH };