I'm using Next.js with "Express.js" to serve authentication-protected web pages.
We have an auth middleware in our "server.js" defined as follows:
server.use(
/\/private((\/)?$|\/_next\/data\/.*)/, // exclude sub-path of /preferiti but include /private/_next/data/...
authMiddleware(),
);
The middleware calls our external authentication service; to avoid calling it also for static assets we have implemented a regexp that exclude sub-path of our page (private).
In your opinion, exists a more general way to say: "apply this middleware only for the web pages"?