Reputation: 41
I am trying to create a subdomain in angular 6 using the below method.
For example:
localhost:4200
client1.localhost:4200
client2.localhost:4200
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);
}
Kindly suggest me any other option to create a subdomain in angular 6.
Upvotes: 2
Views: 4408
Reputation: 109
For development purpose you can add sub domain in etc/host file (C:\Windows\System32\drivers\etc\hosts) like below.
127.0.0.1 client1
::1 client1
127.0.0.1 client2
::1 client2
Serve application by using command:-
ng serve --host client1 --port 4300 --open
ng serve --host client2 --port 4400 --open
Upvotes: 3