I am writing an ionic application which makes REST api calls to GET, POST, etc. I want to externally set the IP EndPoint and use it everywhere. So if the service ip changes, I need not to change ip address in every $http. How to set the API’s EndPoint in config.xml? Help out guys…
I don’t know of any way that REST API address can be specified in config.xml. config file is for native settings and REST API calls are being made using JS. If you want flexibility regarding Server address then instead of hardcoding baseURL in in your $http use constants
and inject it in the services where you make Server calls. Using Constants instead of hard coding things is a good practice.
You could try to put your address in app preferences.
Other simpler possibility: use a domain name rather than an IP address and let DNS do the work.
this is nice!! Thank you…
Thanks gmarziou for your solution!
You can achieve that in many different ways, one of which using
Refer to this article: http://atticuswhite.com/blog/angularjs-configuration-with-gulpjs/
Bare in mind that gulp tasks will be modifying your files when using
ionic serve, given that you modified your
ionic.project with the gulp tasks.
ionic build, you would need to run the gulp task first then call
Another solution is to use cordova hooks -> (https://blog.nraboy.com/2015/01/hooks-apache-cordova-mobile-applications/)