Add flags middleware to next wrapper