feat(pdf-viewer): add proxy endpoint to bypass CSP for PDF loading

- Created /api/pdf-proxy route
- PDF viewer now uses proxy for URL loading
- Bypasses Content-Security-Policy restrictions
This commit is contained in:
2026-03-23 22:27:36 +01:00
parent f947ed6063
commit 9c017b5967
2 changed files with 53 additions and 38 deletions
+29
View File
@@ -0,0 +1,29 @@
import { NextResponse } from "next/server";
export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const url = searchParams.get("url");
if (!url) {
return NextResponse.json({ error: "No URL provided" }, { status: 400 });
}
try {
const response = await fetch(url);
if (!response.ok) {
return NextResponse.json({ error: "Failed to fetch PDF" }, { status: response.status });
}
const arrayBuffer = await response.arrayBuffer();
return new NextResponse(arrayBuffer, {
headers: {
"Content-Type": "application/pdf",
"Content-Disposition": "inline",
"Cache-Control": "public, max-age=3600",
},
});
} catch (error) {
return NextResponse.json({ error: "Failed to fetch PDF" }, { status: 500 });
}
}