Add middleware to allow env switching