title: Creating environment independant code with Angular.js
body: <p>We are using Angular with Bower with a Python API for our stack. We have multiple environments that the code runs in - dev, staging, prod, etc. As of right now, we have to manually change connection strings for the front-end after we push fresh code to it to accommodate the environment it's in - but obviously that's not the right way to do things. To elaborate, say, we have following hosts for the front end: <code>www.something.com</code> and <code>www.test-something.com</code> and they should connect to <code>apisomething.com</code> and <code>test-apisomething.com</code> to pull data, respectively.</p>
  
  <p>My objective is to be able to deploy code to any of the environments without having to change any values. Usually, I'd use environment variables on the server side to create all the links, but since Angular runs in a browser, those variables can't be accessed. So I am not sure how to proceed.</p>
  
  <p>My research came up with tutorials using Grunt <a href="http://mindthecode.com/how-to-use-environment-variables-in-your-angular-application" rel="nofollow">here</a> and <a href="http://www.ng-newsletter.com/advent2013/#!/day/5" rel="nofollow">here</a> but since we aren't using Grunt, that's not working out.</p>
  
  <p>My thought is to write a Python script to manually generate a <code>"constants.js"</code> in the same directory as the <code>app.js</code> file resides (it would have to be run once for each environment) and include that file into <code>git.ignore</code>. The script will take a parameter and basically be a one-liner: <code>"var base_url = \"www.something.com\""</code> where the value of <code>base_url</code> will vary with the parameter passed into the script. This is as far as I have gotten. </p>
  
  <p>So, here are the questions:</p>
  
  <ol>
  <li>Is there a better way? </li>
  <li>If not, what is the best way to make the
  value of <code>base_url</code> accessible in the Angular app? Service, module, etc? And how would that work?</li>
  </ol>