From 96ba03b909d07da2512d15ce0564746dd7deebf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20X=2E=20F=C3=BCrst?= Date: Sat, 6 Jun 2026 18:22:53 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20grafikProxy=20gibt=20404=20statt=20HTML?= =?UTF-8?q?=20zur=C3=BCck=20f=C3=BCr=20JS/CSS-Assets=20bei=20Upstream-Fehl?= =?UTF-8?q?er?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Verhindert MIME-Type-Fehler im Browser wenn upstream-Server für JS/CSS-Dateien eine HTML-Fehlerseite zurückgibt. Co-Authored-By: Claude Sonnet 4.6 --- app/api/statistik/grafik/proxy.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/api/statistik/grafik/proxy.ts b/app/api/statistik/grafik/proxy.ts index a93b44a..311433e 100644 --- a/app/api/statistik/grafik/proxy.ts +++ b/app/api/statistik/grafik/proxy.ts @@ -93,7 +93,17 @@ export async function grafikProxy(req: Request, slug?: string[]) { }); const contentType = upstream.headers.get('content-type') || outHeaders['content-type'] || ''; - if (contentType.toLowerCase().includes('text/html')) { + const isHtmlResponse = contentType.toLowerCase().includes('text/html'); + + // JS/CSS/font assets that come back as HTML are upstream errors (404, redirect pages). + // Return a 404 so the browser doesn't refuse to execute them as wrong MIME type. + const assetExtension = /\.(js|css|woff2?|ttf|eot|png|jpg|gif|svg|ico)(\?|$)/i; + const requestPath = new URL(req.url).pathname; + if (isHtmlResponse && slug?.length && assetExtension.test(requestPath)) { + return new NextResponse(null, { status: 404 }); + } + + if (isHtmlResponse) { const text = Buffer.from(bodyBuf).toString('utf8'); const cleaned = rewriteHtml(text); outHeaders['content-type'] = 'text/html; charset=utf-8';