I figured it out, the wording in the doc is misleading: if you are writing middleware for an endpoint only, do not register that middleware inside config/middleware.ts, doing so will cause the middleware to be called multiple times in a single request.
Don’t listen to the last line here if you are creating route-only middleware.
