Skip to content

Commit

Permalink
introduce 'CAT_API_SERVICE_DEFAULTS' constant to allow configuration …
Browse files Browse the repository at this point in the history
…of the endpoint url prefix
  • Loading branch information
tsalzinger committed Jun 17, 2015
1 parent 7cea89f commit 7d704d2
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/main/javascript/service/cat-api-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ function EndpointConfig(name, config) {

function CatApiServiceProvider() {
var _endpoints = {};
var _urlPrefix = '/api/';

/**
* This method is used to either create or retrieve named endpoint configurations.
Expand All @@ -318,11 +317,11 @@ function CatApiServiceProvider() {
};


this.$get = ['$http', 'catConversionService', 'catSearchService',
this.$get = ['$http', 'catConversionService', 'catSearchService', 'CAT_API_SERVICE_DEFAULTS',
/**
* @return {object} returns a map from names to CatApiEndpoints
*/
function $getCatApiService($http, catConversionService, catSearchService) {
function $getCatApiService($http, catConversionService, catSearchService, CAT_API_SERVICE_DEFAULTS) {
var catApiService = {};

var dynamicEndpoints = {};
Expand All @@ -342,14 +341,14 @@ function CatApiServiceProvider() {
if (_.isUndefined(settings)) {
throw new Error('Undefined dynamic endpoint settings');
}
dynamicEndpoints[name] = new CatApiEndpoint(_urlPrefix,
dynamicEndpoints[name] = new CatApiEndpoint(CAT_API_SERVICE_DEFAULTS.endpointUrlPrefix,
new EndpointConfig(name, settings), $http, catConversionService, catSearchService);
}
return dynamicEndpoints[name];
};

_.forEach(_.keys(_endpoints), function (path) {
catApiService[path] = new CatApiEndpoint(_urlPrefix, _endpoints[path], $http, catConversionService, catSearchService);
catApiService[path] = new CatApiEndpoint(CAT_API_SERVICE_DEFAULTS.endpointUrlPrefix, _endpoints[path], $http, catConversionService, catSearchService);
});

return catApiService;
Expand All @@ -366,7 +365,10 @@ function CatApiServiceProvider() {
*
* @constructor
*/
angular.module('cat.service.api', ['cat.service.conversion', 'cat.service.search']).provider('catApiService', CatApiServiceProvider);
angular
.module('cat.service.api', ['cat.service.conversion', 'cat.service.search'])
.constant('CAT_API_SERVICE_DEFAULTS', {endpointUrlPrefix: '/api/'})
.provider('catApiService', CatApiServiceProvider);

/**
* @ngdoc service
Expand Down

0 comments on commit 7d704d2

Please sign in to comment.