Create the middleware