Next.js progress - middleware

I'm learning how to create middleware in Next.js app router. https://nextjs.org/docs/app/building-your-application/routing/middleware There's one middleware per project which was WTF for me, but they write that you could put some ifs in your codebase: https://nextjs.org/docs/app/building-your-application/routing/middleware#conditional-statements so maybe it's not a limitation after all.

First I used NextResponse.redirect but this changed my URL so I used NextResponse.rewrite so I am returning some content but URL stays the same

I haven't play with cookies or headers yet

And authentication - big thing to know.

Besides I wonder where to put data fetching in my SSG app. I'm making something that read some files on disk and I don't want to fetch same JSON file over and over. I thought maybe I could read data in middleware and pass to views but I think this is not really how you should do it in Next.js (well, there's possibility to pass data to routes via params, but I need some bigger data)

Next.js is somewhat more complex than I thought. But still, I think it's an easy framework, but not everything is clear at first.

Comments

Popular posts from this blog

Communication skills in a team.