add middleware to publishing