Next.js Discord

Discord Forum

Middleware.js use problem

Answered
Spotted Rail posted this in #help-forum
Open in Discord
Original message was deleted.
Answered by Jimmy Barton
Use the file middleware.ts (or .js) in the root of your project to define Middleware. For example, at the same level as pages or app, or inside src if applicable.

https://nextjs.org/docs/app/building-your-application/routing/middleware

@Spotted Rail I think you're supposed to put that middleware file inside src if you're using src folder.
View full answer

2 Replies

Use the file middleware.ts (or .js) in the root of your project to define Middleware. For example, at the same level as pages or app, or inside src if applicable.

https://nextjs.org/docs/app/building-your-application/routing/middleware

@Spotted Rail I think you're supposed to put that middleware file inside src if you're using src folder.
Answer