如何在Angular 2(路由器3)中处理租户子域 [英] How to handle tenant subdomains in Angular 2 (router 3)

查看:83
本文介绍了如何在Angular 2(路由器3)中处理租户子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在Angular 2(RC6,路由器3.0)中获取tenant.app.com设置

Trying to get tenant.app.com setup in Angular 2 (RC6, Router 3.0)

是否有有关如何执行此操作的文档?我见过的几乎所有内容都以基本url =/开头,然后从基本url解析该URL.

Is there any documentation around how to do this? Almost everything I've seen starts with a base url = / and then parses the url from the base url.

我需要为非登录用户提供一个www版本,然后为所有登录用户提供一个租户驱动的子域

I need to have a www version for the non-signedin user and then tenant driven subdomains for all loggedin users

推荐答案

我认为我有一种可行的方法. getSubdomain()允许我在NgInit()上的app.component.ts中查询子域,并且可以使用该子域将用户的登录范围限制在与该子域相关联的tenant_id上

I think I have an approach that's working. getSubdomain() allows me to query the subdomain in app.component.ts on NgInit() and I can use that to scope the sign in for the user against a tenant_id tied to the subdomain

getSubdomain() {
  const domain = window.location.hostname;
  if (domain.indexOf('.') < 0 || 
    domain.split('.')[0] === 'example' || domain.split('.')[0] === 'lvh' || domain.split('.')[0] === 'www') {
    this.subdomain = '';
  } else {
    this.subdomain = domain.split('.')[0];
  }
  console.log('subdomain', this.subdomain);
}

这篇关于如何在Angular 2(路由器3)中处理租户子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆