Adds environment-switching middleware.