An issue I'm facing with the app I'm developing is that users need to be able to change the IP address of the server where the REST API is hosted. The challenge lies in the fact that while the address is stored in a variable that can be changed, the base URL cannot be altered once the services are instantiated. Despite finding a solution on Stack Overflow for changing the URL of some services, POST actions remain a problem.
I've attempted various configurations, but encountered errors each time. For instance:
// Services file
app.factory('Bookings', BookingsFactory)
function BookingsFactory($resource, GlobalVariables) {
return $resource('http://:url/api/bookings/:id/', null, {url: '@url'});
}
//Controllers file
Bookings.save(booking, {url: GlobalVariables.IPServer});
This results in an error message "net::ERR_NAME_NOT_RESOLVED" because the request URL is incorrect. It appears as "".
Another attempt:
//Services file
app.factory('Bookings', BookingsFactory)
function BookingsFactory($resource, GlobalVariables) {
return $resource('http://:url/api/bookings/:id/', {url: '@url'});
}
//Controllers file
Bookings.save({booking: booking, url: GlobalVariables.IPServer});
However, this results in a 400 BAD REQUEST error, prompting for content in all required fields: "This field is required."
Currently using AngularJS v1.3.13, my aim is to find a method to modify the base URL for every request made, including POST requests. Alternatively, I am exploring options to update the URL in each factory of the application after it has been initialized. Is there a feasible solution for either scenario?