1

I have an angular constant which defines webservice end point

angular.module('myModule').constant('mywebservice_url', 'http://192.168.1.100')

The problem is that for dev I have a different end point while staging and production its different. Every time I try to check in to git I have to manually reset this file.

  1. Is there any way git permenantly ignore this file but checks out the file while clone or checkout?
  2. Is there any way I can make angular pickup file dynamically from something like environment variable.

NOTE: I don't want to depend on server to do this, ie I don't want to use apach SSI or any of those technologies as it will work only one set of servers.

Neo
  • 4,550
  • 6
  • 34
  • 51

2 Answers2

4
  1. Delaying the injection via backend processing. I usually just create a global object on html page called pageSettings which values like this is getting injected from the backend, i.e. environment variables, etc. and just pass that global pageSettings object into that angular constant or value.

  2. Build system injection. If you don't have a backend, i.e. pure SPA... maybe you can put this inside your build system, i.e. create multiple task for building the different environments in gulp or grunt and replace that value during the build process.

Jimmy Chandra
  • 6,472
  • 4
  • 26
  • 38
  • Mine is pure SPA which is completly independant on backend. The problem with gulp and grunt is that I won't have control over all evnironment, i.e. when we install in clients system I won't have ablity to run gulp there. So there is no other way other than using build system like gulp or grunt? – Neo May 11 '15 at 05:15
  • 1
    In any case, beside those 2 options I can't think of anything else at this moment. Most of the time, I'd not imagine running gulp or grunt on client system. I'd imagine, you'd packaged the already built version and distribute that to the client. If not, the only other thing that I can do so is kind of like consulting module or client self service module where they have to provide the endpoint on first run and that get persisted afterward for future runs. – Jimmy Chandra May 11 '15 at 05:23
0

In e.a. your app init code:

var x = location.hostname;

Then define 2 different constants. One based off the domain name of your develop environment and one for your production.

therebelcoder
  • 929
  • 11
  • 28
  • This is kind of HACK as if i change domain or in my case I have multiple clients then it will become hectic. – Neo May 11 '15 at 05:15