title: Getting hostname during SSR
body: <p>I am writing an app which has a client and an api at different domains, something like this:</p>
  
  <p>[local]</p>
  
  <p>localhost:5000 (client)</p>
  
  <p>localhost:5001 (api)</p>
  
  <p>[web]</p>
  
  <p>app.domain.com (client)</p>
  
  <p>api.domain.com (api)</p>
  
  <p>Now, when writing my fetch requests, I'd like to be able to send requests to the localhost api when I make requests from the localhost client, and the web api when requested from the web client. To do this, I have to be able to set my base url, so I am trying to write a getApiDomain method which I can use to pick the right domain.</p>
  
  <pre><code>let fetchTask = fetch(`${Domain.getApiDomain()}/api/Item/${id}`)...
  </code></pre>
  
  <p>My method looks like this:</p>
  
  <pre><code>export abstract class Domain {
      public static isLocalhost = Boolean(window.location.hostname === 'localhost' );
  
      public static getApiDomain(): string {
  
          return this.isLocalhost
              ? "http://localhost:5001"
              : "http://api.domain.com";
      }
  }
  </code></pre>
  
  <p>This works well for the client, but I can't get it to work on the server during SSR due to the use of window. How can I get the hostname while executing on the server?</p>