Pages middleware with nextjs and wrangler pages dev

Hello, I have a nextjs app, that uses app router. I've tried adding pages middleware to it, but I just cannot get it to work locally. I've added functions/_middleware.ts file in the root of the project, right next to package.json. It's just an example copied over from the docs with an additional console.log. I run command: pnpm wrangler pages dev When I hit any route, I don't see any logs from my middleware. What kinda worked is running wrangled command like this: pnpm wrangler pages dev .next/static - now middleware gets hit and I see the logs, but any route I try to access, I get 404s. What am I missing?
1 Reply
Rokas
RokasOP2mo ago
oh, if I do pnpm wrangler pages dev .next/static even without middleware app returns 404s Okay, so found a solution. I should've followed nextjs docs, not pages docs. In order for middleware to work, it needs to be added to src folder named middleware.ts .
Want results from more Discord servers?
Add your server