title: How to get full base URL (including server, port and protocol) in Angular Universal?
body: <p>I need to get the full base URL (e.g. http://localhost:5000 or <a href="https://productionserver.com" rel="nofollow noreferrer">https://productionserver.com</a>) of my Angular 2 app so that I can pass it along to a 3rd party service in the context of the app. The app's location varies depending on whether it is development, various staging/testing environments, or production, and I'd like to detect it dynamically so I don't need to maintain a hard-coded list.</p>
  <p>A <a href="https://stackoverflow.com/questions/36222845/how-to-get-domain-name-for-service-in-angular2">similar question</a> has been posted in the past, but the answers (i.e. use some version of the window.location.hostname or window.location.origin property) only work when the angular2 app is being rendered by the browser.</p>
  <p>I would like my app to work with Angular Universal, which means it needs to be rendered on the server-side where there is no access to DOM objects like <code>window.location</code>.</p>
  <p>Any ideas on how to accomplish this? For reference, using <code>asp.net core</code> as the back-end (using the default <code>dotnet</code> new angular template).</p>