I have 3 Domain names hosted with Godaddy, They all point at the same server hosting my angular 2 app, Is there a way to check the header of the request to determine which of the 3 domains the user is coming from?
1 Answer
Your request is out when your Angular application is starting. So you can't parse your headers here.
I suggest you to prefer a request param that you add in your Godaddy hosted apps request, and then parse it in an Angular component with @angular/router like this :
import {Router, ActivatedRoute, Params} from '@angular/router';
import {OnInit, OnDestroy, Component} from '@angular/core';
@Component({...})
export class YourComponent implements OnInit {
constructor(private activatedRoute: ActivatedRoute) {}
ngOnInit() {
this.activatedRoute.params.subscribe((params: Params) => {
let origin= params['origin'];
console.log(origin);
});
}
}
Alternatively, you could parse the request param with a pure Javascript on page loading (location.search...).
If you cannot edit the Godaddy hosted apps requests, you will have to configure a reverse proxy on the server which serve your Angular app.
1 Comment
Kevin192291
Exactly what I was looking for, Thank you Karbos!
headerwhat you refer to?