building the middlewares stack