diff --git a/middleware.ts b/middleware.ts index 2261faad..62cd5429 100644 --- a/middleware.ts +++ b/middleware.ts @@ -52,16 +52,20 @@ export default async function middleware(request: NextRequest) { urlObj.protocol = proto; - effectiveRequest = new NextRequest(urlObj, { - headers: request.headers, - method: request.method, - body: request.body, - }); + // Only create a new request for GET/HEAD to avoid consuming the body stream on POST/PUT + // This resolves the "failed to pipe response" error (160k occurrences in GlitchTip) + if (['GET', 'HEAD'].includes(request.method)) { + effectiveRequest = new NextRequest(urlObj, { + headers: request.headers, + method: request.method, + // No body for GET/HEAD + }); - if (process.env.NODE_ENV !== 'production' || !process.env.CI) { - console.log( - `🛡️ Proxy: Fixed internal URL leak: ${url} -> ${urlObj.toString()} | Proto: ${proto} | Host: ${hostHeader}`, - ); + if (process.env.NODE_ENV !== 'production' || !process.env.CI) { + console.log( + `🛡️ Proxy: Fixed internal URL leak: ${url} -> ${urlObj.toString()} | Proto: ${proto} | Host: ${hostHeader}`, + ); + } } }