Next.js Discord

Discord Forum

middleware cause 400 error on routes

Unanswered
Sloth bear posted this in #help-forum
Open in Discord
Sloth bearOP
Hi
I have a hot problem in production.
My middleware file cause 400 bad requeat error in app rourtes!
And this problem is shown after we moved to HTTPS from HTTP. everything was OK on HTTP.

I forced to remove middleware file for now...
Do you have any idea how to fix this??

32 Replies

American Chinchilla
You would have to share your middlewarenwith us
Middleware*
Pygmy Nuthatch
This feels like a problem in the reverse proxy, next js https is experimental so i would have to see your architecture and middleware to conclude @Sloth bear
Sloth bearOP
@Pygmy Nuthatch @American Chinchilla

I have this problem even if i have a simple middleware like :
export function middleware(request: NextRequest) {
   return NextResponse.next()
}


My structure is :
src
   app
   components
   middleware.ts
Pygmy Nuthatch
Ok but how is the traffic routed to the server
Sloth bearOP
I did not understand
Pygmy Nuthatch
Is the next instance in https mode
Im isking if the traffic is decrypted before it hits the server
Sloth bearOP
I did not touch my next config for https.
I was always worked with http.
The funny thing is when i remove my middleware, problem is gone and routes are ahown.
But when i put middleware my route and chunks are not load.
I have no idea what to do ;((
Pygmy Nuthatch
Huh well that is essential info
Sloth bearOP
What info yoh need? Tell me to give it to you
Pygmy Nuthatch
Wait
Do you have a matcher
Sloth bearOP
Nope.
I was added matcher too. no effect
Pygmy Nuthatch
What
This may be a bug
Yeah bro sorry this is the end of my knowledge
Sloth bearOP
Bug of what? Next?
Thanks bro 🙂
@Sloth bear Bug of what? Next?
Pygmy Nuthatch
I would think
American Chinchilla
export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - api (API routes)
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico, sitemap.xml, robots.txt (metadata files)
/
'/((?!api|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).
)',
],
}
If this doesn’t work
Then yeah not sure
In middleware add that*^
At bottom
Sloth bearOP
Still have the problem :((
Could it be the cloudflare issue??
@Sloth bear Could it be the cloudflare issue??
Pygmy Nuthatch
Its possible but if it works without middleware i doubt it
Sloth bearOP
Problem solved!
It was from webserver and haproxy(DevOps issues)

Thank you guys
Sloth bearOP
Damn
It was Nextjs bug😧

Look at here :
https://github.com/vercel/next.js/issues/58764
Sloth bearOP
@Pygmy Nuthatch you were right... It's Nextjs bug