Only compile middleware for the current mode.

Signed-off-by: Yorick Peterse <yorickpeterse@gmail.com>