Next.js Discord

Discord Forum

NextRequest Context problem

Unanswered
Russian Spaniel posted this in #help-forum
Open in Discord
Avatar
Russian SpanielOP
I would like to understand a behavior in my NextJS application.

For each request a middleware is launched, which looks like this:

export async function middleware(request: NextRequest) {
   request.headers.set('Custom-Header', 'Custom-Value');
   ...
}

Then a custom route is called (route handler):
export async function GET(request: NextRequest) {
   const customHeaderValue = request.headers.get('Custom-Header');
   console.log(customHeaderValue); // null
}


Could you explain to me why I don't have access to the data defined in the middleware in the GET route ?
So I tried to set various values, but nothing works, and from what I understood the NextRequest object is the context of the current request.

0 Replies