Make virtualhosting url generation not fail in a non-wsgi env

This is mostly useful in situations where the JSON serialization
is being used on the twanager side of the world (notably the
dispatcher listener used for websockets).