Debug flag middleware