How to handle tenant subdomains in Angular 2 (router 3)

余生长醉 提交于 2020-01-02 10:01:40

问题


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

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.

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


回答1:


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);
}


来源:https://stackoverflow.com/questions/39431009/how-to-handle-tenant-subdomains-in-angular-2-router-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!