When using http in Angular the url must be specified in the JavaScript. I don't want to hard code the full url (e.g. http://www.example.com/Controller/GetDetails/) because this would mean code changes between live and test environments.
I've read examples that just use the relative path (e.g. /Contoller/GetDetails), however due to the way MVC routing works this often fails to work. As a simple example the home page can be accessed via:
and so adding the relative path isn't ideal because two out of three of these routes will get the wrong http url.
I thought initially that I could determine the base url from JavaScript and use:
window.location.protocol+"//"+window.location.host + "/Contoller/GetDetails"
But I have found that this fails if the MVC application is running in a folder and won't correctly resolve a url like:
http://www.example.com/MyApplication/Controller/GetDetails
I also considered using a more RESTful approach and handing all the urls needed for the JavaScript down as part of the json data - but of course, this leads to the chicken and egg situation of: If the http urls are provided in the json, how do I get the first json call to work?
What is a robust way of getting urls for use in AngularJS http calls to mvc.net?