Reputation: 775
I am using angular.js and I have a module which uses a web service
/* Rest WS Config */
RestangularProvider.setBaseUrl(ENVL.apiEndpoint+'/ig-web/services');
It works fine.
I would like to use the relative way of setting my base URL (beacuse I must not provide a specific configuration per environment) so I tried:
RestangularProvider.setBaseUrl('/ig-web/services');
RestangularProvider.setBaseUrl('./ig-web/services');
But that did not work.
Any ideas ?
Herehunder the complete module file
'use strict';
angular.module('env.config', [])
.constant('ENVL', {
'name': 'development local',
'apiEndpoint': 'http://localhost:8080'
})
.constant('DEVT', {
'name': 'development server',
'apiEndpoint': 'http://domain.dev'
})
.constant('INT', {
'name': 'integration server',
'apiEndpoint': 'http://domain.int'
})
.constant('REC', {
'name': 'recette server',
'apiEndpoint': 'http://domain.rec'
});
var app = angular.module('saisinesApp', [
'ngAnimate',
'ngResource',
'ui.bootstrap',
'toaster',
'angular.css.injector',
'angularFileUpload',
'dialogs',
'ui.router.state',
'ajoslin.promise-tracker',
'cgBusy',
'restangular',
'ngGrid',
'xeditable',
'env.config',
'saisinesAppFilters'])
.constant('_', window._)
.constant('jsPDF',window.jsPDF);
app.config(function ($stateProvider, $urlRouterProvider, RestangularProvider,ENVL) {
/* Rounting config*/
$urlRouterProvider.when('/home', '/home/search');
$stateProvider
.state('auth', {
url: '/',
templateUrl: 'src/auth/authentication.html',
controller: 'AuthCtrl'
})
.state('auth-by-url', {
url: '/:token',
templateUrl: 'src/auth/authentication.html',
controller: 'AuthCtrl'
})
.state('home', {
abstract: true,
url: '/home',
templateUrl: 'src/common/header.html',
controller: 'HeaderCtrl'
})
.state('home.search', {
url: '/search',
templateUrl: 'src/search/search.html',
controller: 'SearchCtrl'
})
.state('home.search-by-siren', {
url: '/search/:siren',
templateUrl: 'src/search/search.html',
controller: 'SearchCtrl'
})
.state('home.create', {
url: '/create',
templateUrl: 'src/create/create.html',
controller: 'CreateCtrl'
})
.state('home.recap', {
url: '/recap',
templateUrl: 'src/recap/recap.html'
});
$urlRouterProvider.otherwise('/');
/* Rest WS Config */
//RestangularProvider.setBaseUrl(ENVL.apiEndpoint+'/ig-web/services');
RestangularProvider.setBaseUrl('./ig-web/services');
});
app.run([
'$rootScope', '$state', '$stateParams', function($rootScope, $state, $stateParams) {
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;
}
]);
Upvotes: 0
Views: 766
Reputation: 775
OK, I hope it will help someone if they have the same problem.
When I was testing in local, I was using a grunt server with the port 8000
But my web services were located on the port 8080 (which corresponds to the ENV constant).
Thus there was no way that my web services could work with the port of grunt if I let the relative path.
However, when using JBOSS and the relative path, it works because now the relative path points to the correct adress.
Thus my correct configuration is:
'use strict';
var app = angular.module('saisinesApp', [
'ngAnimate',
'ngResource',
'ui.bootstrap',
'toaster',
'angular.css.injector',
'angularFileUpload',
'dialogs',
'ui.router.state',
'ajoslin.promise-tracker',
'cgBusy',
'restangular',
'ngGrid',
'xeditable',
'saisinesAppFilters'])
.constant('_', window._)
.constant('jsPDF',window.jsPDF);
app.config(function ($stateProvider, $urlRouterProvider, RestangularProvider) {
/* Rounting config*/
$urlRouterProvider.when('/home', '/home/search');
$stateProvider
.state('auth', {
url: '/',
templateUrl: 'src/auth/authentication.html',
controller: 'AuthCtrl'
})
.state('auth-by-url', {
url: '/:token',
templateUrl: 'src/auth/authentication.html',
controller: 'AuthCtrl'
})
.state('home', {
abstract: true,
url: '/home',
templateUrl: 'src/common/header.html',
controller: 'HeaderCtrl'
})
.state('home.search', {
url: '/search',
templateUrl: 'src/search/search.html',
controller: 'SearchCtrl'
})
.state('home.search-by-siren', {
url: '/search/:siren',
templateUrl: 'src/search/search.html',
controller: 'SearchCtrl'
})
.state('home.create', {
url: '/create',
templateUrl: 'src/create/create.html',
controller: 'CreateCtrl'
})
.state('home.recap', {
url: '/recap',
templateUrl: 'src/recap/recap.html'
});
$urlRouterProvider.otherwise('/');
/* Rest WS Config */
RestangularProvider.setBaseUrl('/ig-web/services');
});
app.run([
'$rootScope', '$state', '$stateParams', function($rootScope, $state, $stateParams) {
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;
}
]);
Upvotes: 1