Middleware matcher help

Hi all, I’m a little confused about middleware matchers.

I’m about to start building a session handling solution using JWT and it makes sense to use middleware for this (thanks @leerob for the YouTube video btw)

I see the docs show an example where we match all routes except api, _next/static, _next/image, and also favicon.ico.

I’m using the new opengraph file naming convention for a lot of my routes (a bunch of different opengraph-image.png files exist in the project). I also have a web manifest.json at the root as well., and apple-icon.png.

Do each of these need to be declared in the matcher too? Or do they get moved to _next/static during build? (If so, why doesn’t favicon.ico? or does it?)

I don’t like the thought of having a really really long matcher that has to declare that each one of my opengraph images gets ignored. I will have to keep adding additional files to it.

I’m using server components for most of my data fetching, and server actions for forms and mutations. I plan to still useSWR for some areas where data needs to be polled though (ie. notifications bell will continuously ask if there are any new notifications to display), so I’m still using /api/ routes for a couple of things and /api should not be ignored.

Just wondering how best to handle this. I really want my middleware to run on all routes, ignoring all static assets. Seems a little strange that middleware would ever run on static assets in the first place (what is the use case for this?)

Thanks

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.