fixing router to be middleware friendly