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';