title: Configure backend API path in static served content
body: <p>I've built an web application that contains two parts: a static served frontend and a REST API backend. At the moment the frontend has an hardcoded API path, which is fine for the development process because both instances run on the same machine. So, on the client side one Angular2 service provides the property:
  <code>this.apiServer = "http://127.0.0.1:3000/api/v1";</code></p>
  
  <p>Now, I want to deploy this application. The frontend only contains static files, so I want to keep things as simple as possible and outsource the serving job (e.g. serve a static website with Amazon S3).
  The backend should run on another machine. Of course I could change the hardcoded path to the backend server's IP but I don't think this is the right way. Especially because this will break my development flow.</p>
  
  <p>I thought about the following short term solution: If Angular2 runs in development mode use <code>localhost</code>, otherwise use <code>&lt;ip-to-backend&gt;</code>, but this seems also a little bit hacky. </p>
  
  <p>If I have access to the frontend server I might redirect API requests (like <a href="https://stackoverflow.com/questions/39900998/hosting-static-angular2-app-on-nginx-and-proxying-http-requests-to-backend-api">here</a>), but I can't assume that I'll always have that access.</p>
  
  <p>Is there any way to avoid the hardcoded api path and serve the frontend as static content without touching it? </p>
  
  <p>My research did not succeed but maybe I'm just missing the proper keyword :-)</p>