CORS refactoring

Refactor handling cors for multiple domains. Also refactor name from hosts into domains.