adds middleware function to connect task