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

1

6

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

Lingerie answered 10/9, 2016 at 22:3 Comment(1)
The same here. No info all around and I am getting pretty confused if is supported at all or not.Antecedency
L
10

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);
}
Lingerie answered 27/3, 2017 at 21:43 Comment(1)
simple solution. I prefer to do the split once at the start and to check the length of the array after instead of indexOf, but it does not really matter at the endCoreen

© 2022 - 2024 — McMap. All rights reserved.