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.

Answers


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.


Need Your Help

visual studio add in to get information of the project and pass it to existing c# program and display results in views

c# visual-studio-2010 add-in

I am from Java backgroud and have very little knowledge about .net. We have a application written in c# that scans source code files and calculate various things like code metrics defect density and

Data Binding Order of Operations for Caliburn Micro Xamarin

c# mvvm data-binding xamarin caliburn.micro

What is the "Order of Operations" (OOP) for Data Binding in Caliburn.Micro Xamarin Android (Mono.Android)?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.