That URL structure assumes you have a single app running at the domain. So I am going to assume that is the case.
first of all you have to map the tenant name ($domain) into request.args(0) using routes.py
routes_in = [['/$domain','/yourapp/default/index/$domain'],
['/$domain/$c','/yourapp/$c/index/$domain'],
['/$domain/$c/$f','/yourapp/$c/$f/$domain'],
['/$domain/$c/$f/$anything','/yourapp/$c/$f/$domain/$anything']]
routes_out = [(a,b) for (b,a) in routes_in]
then you have to handle in code where the domain is now in request.args(0).