modified the middleware function to pass e2e test again