I am creating a service where other companies can host a community at companyname.mydomain.com . I have a Redux reducer called company , which contains a certain state about this company. I would like to be able to get data about this company isomorphically based on the requested subdomain.
If I have a getSubdomain function:
function getSubdomain(host) { const hostWithoutPort = host.split(':')[0]; return hostWithoutPort.split('.').slice(0, -2).join('.'); }
Then on the client I got a subdomain by doing:
const subdomain = getSubdomain(window.location.host);
On the server, since the window is not available, and the host is different for each request, I would do:
const subdomain = getSubdomain(request.headers.host);
What is the right strategy to correctly extract company data based on this subdomain? I think maybe I could initialize my store using a subdomain set to state?
source share