Extracted middleware creation from route creation