Next.js Discord

Discord Forum

Middleware not running in prod, but localhost

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

48 Replies

Magnificent FrigatebirdOP
@Anay-208 | Ping in replies on vercel
@Magnificent Frigatebird <@755810867878297610> on vercel
can you send your file structure?
Magnificent FrigatebirdOP
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:
but the actual triggering is not occuring in vercel
Umm, did you try putting a console.log on middleware to verify?
Magnificent FrigatebirdOP
Yes:
Which route do you face this issue in? is that route cached or something?
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
can you send the matcher of your middleware? I'll check it out tmr
Magnificent FrigatebirdOP
export const config = {
  matcher: [
    '/((?!api|_next/static|_next/image|favicon.ico|public|upgrade|account/membership).*)',
  ]
}
Thanks, Also, take a look at this for future ref
Magnificent FrigatebirdOP
My bad!
Alright, will check this out tmr!
And @Magnificent Frigatebird whats your nextjs version?
Magnificent FrigatebirdOP
@Anay-208 | Ping in replies was on 14, updated to stable release of 15 and this is still happening
@Magnificent Frigatebird <@755810867878297610> was on 14, updated to stable release of 15 and this is still happening
Will check this out. Can you tell a route on which middleware isn't running and it is supposed to run at?
Magnificent FrigatebirdOP
Ok @Anay-208 | Ping in replies it's been a while but i have information for you
this error is still going on
this is my app organization
interestingly enough, when logging in [slug]
slug favicon.png and other files are getting picked up
so everything is redirecting
which i suspect is why middleware is not working
@Magnificent Frigatebird this is my app organization
Oh I just noticed your file structure. This is expected to happen because it is inside a [slug]. You'll need to start the matcher with it
Magnificent FrigatebirdOP
@Anay-208 | Ping in replies wdym?
not familiar with matches
You can query this to Ai
on creating a matcher
Magnificent FrigatebirdOP
@Anay-208 | Ping in replies but how does that fix this issue?
My favicon keeps falling into the [slug] route
for middleware in [slug] path, you need to include that path in the matcher
Magnificent FrigatebirdOP
i think there's a bit of a miscommunication and i want to clarify:
it's
/
then [slug]

my favicon and other assets are also falling into slugs layout.tsx and executing logic @Anay-208 | Ping in replies
That’s what I told you have to include the slug in the matcher
Magnificent FrigatebirdOP
Yes but nextjs isn't recognizing my middleware
Or check your regex matcher
Giant Angora
is your middleware inside src/app, or src/ . It should be in src/
middleware is running for him in _next app