A custom JS library based on Angular includes various services for clients, structured like so:
angular.module('Services', [
'ngResource'
]).factory('UserService', function($resource) {
return function(whatsonUserId) {
return $resource('/rest/user/:action');
}
}. factory ...
Clients can easily incorporate the library by doing the following:
app.controller('Ctrl', function(UserService) {
...
UserService().doSomething()
}
However, since clients host their HTML on their own URLs, the root URL for MY services is incorrect. To address this, an absolute URL must be supplied to $resource:
return $resource('www.my.server.url/rest/user/:action');
But there are multiple server URLs - staging, development, production environments - some specific to each client.
The query at hand: Is it feasible to implement a generic 'service' where users of the library can define the 'server root' for 'Services'?