#Is there a way I can put my middleware.ts file inside app/

1 messages · Page 1 of 1 (latest)

warped granite
#

It feels odd to put it at the root of my project

dusk urchinBOT
#

Hi @warped granite. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

According to the information provided in the extracts, the middleware.ts file should be placed at the root of your project or inside the src directory if you're using one. It should be at the same level as your pages or app directory. Placing the middleware.ts file inside the app directory is not recommended and may cause issues with your middleware not triggering correctly.

Here is the recommended project structure:

  • my-project
    • middleware.ts
    • app
      • secret-page
        • page.tsx
      • login
        • page.tsx
      • page.tsx

This information is mentioned in the Next.js documentation (https://nextjs.org/docs/app/building-your-application/routing/middleware#convention) and also discussed in a Github issue (https://github.com/vercel/next.js/issues/53630).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: