Adding CORS support
Getting the subdomain from the referer, still support param method.
Refactoring.