Add debug flag to middleware