There is nothing magical about connect/express 'middleware': they are just functions - and you can call them as you would call any other function.
So in your example:
app.use(function(req, res, next){
if (req.query.something) {
middlewareA(req, res, next);
} else {
middlewareB(req, res, next);
}
});
That said, there might be more elegant ways of constructing hierarchical express applications. Check out TJ's video
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…