Extract app with middleware to make tests pass