3

Have an project that uses Ionic Framework and also $http services. When I'm in development environment need to use the development url api and in production need to use the production url api. I isolated already the base Url, someting like :

.factory('EventsService', function ($http, $q) { var baseUrl = 'http://development.api.example.com/'; //development api ..... 

Is it possible to store it in an external file somewhere ( something like event.dev.settings.xml) and have also a similar one event.prod.settings.xml and the build process to use the correct one depending on what kind of build I'm making?

Or is another way ?

2
  • 1
    For now, I handle it via a constant that is set depending on whether you're running in a browser/SDK (dev) or in an app (prod), but I'm also interested into a better way to handle it at build time. Commented Sep 28, 2015 at 15:44
  • Think I found the answer to my question.Thanks for all the help. stackoverflow.com/questions/17876439/… Commented Sep 28, 2015 at 23:31

2 Answers 2

2

I allways define a RESOURCES object constant where I set some constants like URLs apis, api keys, ... Like this:

.constant('RESOURCES', { API_URL: 'https://api.mydomain.com/', GCM_ID: '000000000000' } ) 

Then, in the factory definition I inject the RESOURCE constant and I use the constants defined in it.

.factory('EventsService', function ($http, $q, RESOURCES) { $http.get(RESOURCES.API_URL+'method')........ //........... } 

This way, if I'm going to use the app in production I only need to modify the RESOURCES constants.

Sign up to request clarification or add additional context in comments.

Comments

1

I use a web developing proxy for that. In the proxy I have a mapping to the developer URLs, so there is no need to save different URLs for production and developing in the app. I use Charles.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.