Routing middleware for stack