add beforeRoute and afterRoute for register middlewares