add switch to disable/enable middleware