fix(prod): resolve middleware piping error and AI model ID
Some checks failed
Build & Deploy / 🧪 QA (push) Failing after 1m44s
Build & Deploy / 🔍 Prepare (push) Successful in 16s
Build & Deploy / 🏗️ Build (push) Has been skipped
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🧪 Post-Deploy Verification (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 3s
Some checks failed
Build & Deploy / 🧪 QA (push) Failing after 1m44s
Build & Deploy / 🔍 Prepare (push) Successful in 16s
Build & Deploy / 🏗️ Build (push) Has been skipped
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🧪 Post-Deploy Verification (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 3s
This commit is contained in:
@@ -51,12 +51,26 @@ export default async function middleware(request: NextRequest) {
|
||||
const hostHeader = headers.get('x-forwarded-host') || headers.get('host') || fallbackHost;
|
||||
|
||||
urlObj.protocol = proto;
|
||||
|
||||
effectiveRequest = new NextRequest(urlObj, {
|
||||
headers: request.headers,
|
||||
method: request.method,
|
||||
body: request.body,
|
||||
});
|
||||
// Do NOT reconstruct NextRequest for GET/HEAD requests to avoid stream locking/piping errors.
|
||||
// next-intl middleware primarily uses the URL and headers, so a simplified request-like object
|
||||
// or a redirected URL is often enough. For robustness, we only clone if we really have to.
|
||||
if (method === 'GET' || method === 'HEAD') {
|
||||
// In Next.js 15+, we can clone headers but avoid re-passing the body stream.
|
||||
effectiveRequest = new NextRequest(urlObj, {
|
||||
headers: new Headers(request.headers),
|
||||
method: request.method,
|
||||
// No body for GET/HEAD
|
||||
});
|
||||
} else {
|
||||
// For POST/PUT etc, we must be careful. Re-passing the body can only be done once.
|
||||
// If we don't need to fix the URL for the body-reading part, we can skip it.
|
||||
// But usually intl-middleware doesn't care about the body.
|
||||
effectiveRequest = new NextRequest(urlObj, {
|
||||
headers: new Headers(request.headers),
|
||||
method: request.method,
|
||||
body: request.body,
|
||||
});
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== 'production' || !process.env.CI) {
|
||||
console.log(
|
||||
|
||||
Reference in New Issue
Block a user