Middleware is a piece of code that works as a interface between your client and server.
It is used to perform tasks such as authentication, caching, and error handling. If you are new to this concept kindly check nextjs middleware.
Here is a simple example of middleware in nextjs.
Depending on your need you can always edit the middleware file and add or remove routes.