Files
Balázs OrbánandGitHub 1caa58087a fix: correctly set x-forwarded-* in Middleware (#57815)
### What?

Follow-up of #56797

While working on this, I noticed that some logic around stripping internal headers was duplicated, so I did some cleanup too.

### Why?

In #56797 we set these headers, but it only affected Route Handlers, Middleware is still missing them, which is a regression introduced in #52492

(Related: https://github.com/vercel/next-learn/issues/252)

### How?

Move to set these headers up to `base-server.ts` so they are present in Middleware too.

> Note: All headers are set with `??=` to respect the original value if set (with other words, only add these headers if they aren't set yet)

Closes NEXT-
Fixes #52266
2023-11-01 04:36:50 +00:00

15 lines
426 B
TypeScript

import { NextResponse } from 'next/server'
export function middleware(req: Request) {
return NextResponse.next({
headers: {
'middleware-x-forwarded-host':
req.headers.get('x-forwarded-host') ?? 'wrong',
'middleware-x-forwarded-port':
req.headers.get('x-forwarded-port') ?? 'wrong',
'middleware-x-forwarded-proto':
req.headers.get('x-forwarded-proto') ?? 'wrong',
},
})
}