You should put your Next.js middleware.js (or .ts) file in the root of your project. This means that it should be at the same level as your "app" or "pages" folder:
src/ ..└── app/ ....└── ... ..└── middleware.js
There are several ways in which you can verify if the contents of the middleware.js file are being read. One such way is by simply adding a console.log() in the file like so:
// middleware.js
export function middleware() {
console.log('output from middleware.js');
}
You can then check the server logs to see if the output is there.