add middleware and app hook