Next.js Discord

Discord Forum

Middleware not running in prod, but localhost

Unanswered
Magnificent Frigatebird posted this in #help-forum
Open in Discord
Avatar
Magnificent FrigatebirdOP
Absolutely stumped by this. My middleware.ts isn't working in production, but it is working in localhost. Any ideas

21 Replies

Avatar
where are you deploying your app?
Avatar
Magnificent FrigatebirdOP
@Anay-208 on vercel
Avatar
can you send your file structure?
Avatar
Magnificent FrigatebirdOP
Image
once again, I know this middleware is working in localhost (seeing the logs). and when i deploy to vercel, it does pick up the paths:
Image
but the actual triggering is not occuring in vercel
Avatar
Umm, did you try putting a console.log on middleware to verify?
Avatar
Magnificent FrigatebirdOP
Yes:
Image
Avatar
Which route do you face this issue in? is that route cached or something?
Avatar
Magnificent FrigatebirdOP
every single route, middleware doesnt run anywhere
and when i disable cache in chrome nothing changes
I had two ideas:

First one is that caching during upload could be causing this. Have been looking into how to deploy as a hard reset
Second one is that within updateSession, maybe my ENVs aren't being initalized properly causing the whole thing to not run?
But I'm really desparate and speculating at this point LOL
Avatar
can you send the matcher of your middleware? I'll check it out tmr
Avatar
Magnificent FrigatebirdOP
export const config = {
  matcher: [
    '/((?!api|_next/static|_next/image|favicon.ico|public|upgrade|account/membership).*)',
  ]
}
Avatar
Thanks, Also, take a look at this for future ref
Avatar
Magnificent FrigatebirdOP
My bad!
Avatar
Alright, will check this out tmr!
Avatar
And @Magnificent Frigatebird whats your nextjs version?
Avatar
Magnificent FrigatebirdOP
@Anay-208 was on 14, updated to stable release of 15 and this is still happening
Avatar
Will check this out. Can you tell a route on which middleware isn't running and it is supposed to run at?