app.config.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. app.run(function($rootScope, $location) {
  2. $rootScope.$on('$routeChangeSuccess', function() {
  3. $rootScope.currentMenuItem = $location.path() || '/home';
  4. });
  5. });
  6. app.config(['$translateProvider', function($translateProvider) {
  7. // var translations = {
  8. // en: {
  9. // 'Authors': 'Authors'
  10. // },
  11. // ru: {
  12. // 'Authors': 'Автор'
  13. // }
  14. // }
  15. // $translateProvider
  16. // .translations('en', translations.en)
  17. // .translations('ru', translations.ru)
  18. // .preferredLanguage(localStorage.getItem('preferredLanguage') || 'en');
  19. $translateProvider.useStaticFilesLoader({
  20. prefix: 'i18n/',
  21. suffix: '.json'
  22. });
  23. $translateProvider.preferredLanguage(localStorage.getItem('preferredLanguage') || 'en');
  24. }]);
  25. // check authorization
  26. app.config(['$httpProvider', function($httpProvider) {
  27. $httpProvider.interceptors.push(['$q', '$location', function($q, $location) {
  28. return {
  29. request: function(config) {
  30. config.headers = config.headers || {};
  31. if (localStorage.getItem('authToken')) {
  32. config.headers.Authorization = 'Bearer ' + localStorage.getItem('authToken');
  33. }
  34. return config;
  35. },
  36. responseError: function(response) {
  37. if (response.status === 401) {
  38. $location.path('/');
  39. }
  40. return $q.reject(response);
  41. }
  42. };
  43. }]);
  44. }]);