angularjs - Creating environment independant code with Angular.js -


we using angular bower python api our stack. have multiple environments code runs in - dev, staging, prod, etc. of right now, have manually change connection strings front-end after push fresh code accommodate environment it's in - that's not right way things. elaborate, say, have following hosts front end: www.something.com , www.test-something.com , should connect apisomething.com , test-apisomething.com pull data, respectively.

my objective able deploy code of environments without having change values. usually, i'd use environment variables on server side create links, since angular runs in browser, variables can't accessed. not sure how proceed.

my research came tutorials using grunt here , here since aren't using grunt, that's not working out.

my thought write python script manually generate "constants.js" in same directory app.js file resides (it have run once each environment) , include file git.ignore. script take parameter , one-liner: "var base_url = \"www.something.com\"" value of base_url vary parameter passed script. far have gotten.

so, here questions:

  1. is there better way?
  2. if not, best way make value of base_url accessible in angular app? service, module, etc? , how work?

you need use $location service information url of running application.


Popular posts from this blog