Middleware events

This is the app side for #3495.