Routing to subdomains using Sails.js
I'm attempting to create an application in Sails.js where users are routed to a specific subdomain based on a company attribute in their profile.
For example, Jack Smith belongs to company "pluto". If Jack logs in to the application at myapp.com , he would be redirected to the dashboard at pluto.myapp.com.
There seems to be a lot of resources on this for express.js but I can't seem to find a straight answer on how to apply those principles in Sails (see this). I'm a novice in Sails/NodeJs so this is MORE than likely a fault on my part :)
Any help is greatly appreciated.
A lot of articles you find on express will apply to sails, but they can over engineer the problem since you are using authentication.
Your dashboards will change based on user or company settings. Since your dashboard is behind a login, then the sub domain is irrelevant to achieve your goal since the variable that adjusts the data being shown on your dashboard is just as easily found via a session or token depending on how you authenticate.
The simplest answer I can give you to your problem assumes you already have your sub domains routed correctly to your main domain. Then all you have to do is log them in and direct them to the correct sub-domain via res.redirect(subDomain+'.mysite.com'). The dashboard can then be displayed based on their login credentials without really caring what the sub-domain is. In this instance, the sub-domain is merely for decoration.
Now if you want to enforce and make sure the correct sub domain is always displayed for a person's credentials, you can always verify that in a policy.