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.
我正在尝试在Sails.js中创建一个应用程序,用户根据其配置文件中的公司属性将其路由到特定的子域。
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.
例如,Jack Smith属于“pluto”公司。如果Jack登录myapp.com上的应用程序,他将被重定向到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 :)
对于express.js似乎有很多资源,但我似乎无法找到关于如何在Sails中应用这些原则的直接答案(见本文)。我是Sails / NodeJs的新手所以这很可能是我的错:)
Any help is greatly appreciated.
任何帮助是极大的赞赏。
1 个解决方案
#1
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.
我可以为您解决问题的最简单答案假设您的子域已经正确地路由到您的主域。然后你所要做的就是登录并通过res.redirect(subDomain +'。mysite.com')将它们引导到正确的子域。然后可以根据他们的登录凭证显示仪表板,而无需真正关心子域是什么。在这种情况下,子域仅用于装饰。
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.
现在,如果要强制执行并确保始终为个人凭据显示正确的子域,则始终可以在策略中验证该域。
#1
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.
我可以为您解决问题的最简单答案假设您的子域已经正确地路由到您的主域。然后你所要做的就是登录并通过res.redirect(subDomain +'。mysite.com')将它们引导到正确的子域。然后可以根据他们的登录凭证显示仪表板,而无需真正关心子域是什么。在这种情况下,子域仅用于装饰。
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.
现在,如果要强制执行并确保始终为个人凭据显示正确的子域,则始终可以在策略中验证该域。