invoke the middleware function