app.config.js 759 B

12345678910111213141516171819202122232425262728293031
  1. app.run(function($rootScope, $location) {
  2. $rootScope.$on('$routeChangeSuccess', function() {
  3. $rootScope.currentMenuItem = $location.path() || '/home';
  4. });
  5. });
  6. // check authorization
  7. app.config(['$httpProvider', function($httpProvider) {
  8. $httpProvider.interceptors.push(['$q', '$location', function($q, $location) {
  9. return {
  10. request: function(config) {
  11. config.headers = config.headers || {};
  12. if (localStorage.getItem('authToken')) {
  13. config.headers.Authorization = 'Bearer ' + localStorage.getItem('authToken');
  14. }
  15. return config;
  16. },
  17. responseError: function(response) {
  18. if (response.status === 401) {
  19. $location.path('/');
  20. }
  21. return $q.reject(response);
  22. }
  23. };
  24. }]);
  25. }]);