You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.2 KiB

7 years ago
  1. 'use strict';
  2. //var urlapi = "http://localhost:3000/api/";
  3. //var urlapi = "http://192.168.1.36:3000/api/";
  4. var urlapi = "http://37.59.123.45:3000/api/";
  5. // Declare app level module which depends on views, and components
  6. angular.module('webapp', [
  7. 'ngRoute',
  8. 'ngMessages',
  9. 'angularBootstrapMaterial',
  10. 'toastr',
  11. 'app.navbar',
  12. 'app.signup',
  13. 'app.login',
  14. 'app.main',
  15. 'app.search',
  16. 'app.travels',
  17. 'app.users',
  18. 'app.user',
  19. 'app.userLikes',
  20. 'app.travel',
  21. 'app.newTravel',
  22. 'app.notifications'
  23. ]).
  24. config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) {
  25. $locationProvider.hashPrefix('!');
  26. //$routeProvider.otherwise({redirectTo: '/main'});
  27. if((localStorage.getItem('cr_webapp_token')))
  28. {
  29. console.log(window.location.hash);
  30. if((window.location.hash==='#!/login')||(window.location.hash==='#!/signup'))
  31. {
  32. window.location='#!/main';
  33. }
  34. $routeProvider.otherwise({redirectTo: '/main'});
  35. }else{
  36. if((window.location!=='#!/login')||(window.location!=='#!/signup'))
  37. {
  38. console.log('app, user no logged');
  39. localStorage.removeItem('cr_webapp_token');
  40. localStorage.removeItem('cr_webapp_userdata');
  41. window.location='#!/login';
  42. $routeProvider.otherwise({redirectTo: '/login'});
  43. }
  44. }
  45. }])
  46. .config(function(toastrConfig) {
  47. angular.extend(toastrConfig, {
  48. autoDismiss: false,
  49. containerId: 'toast-container',
  50. maxOpened: 0,
  51. newestOnTop: true,
  52. positionClass: 'toast-bottom-right',
  53. preventDuplicates: false,
  54. preventOpenDuplicates: false,
  55. target: 'body'
  56. });
  57. })
  58. .factory('httpInterceptor', function httpInterceptor () {
  59. return {
  60. request: function(config) {
  61. return config;
  62. },
  63. requestError: function(config) {
  64. return config;
  65. },
  66. response: function(res) {
  67. return res;
  68. },
  69. responseError: function(res) {
  70. return res;
  71. }
  72. };
  73. })
  74. .factory('api', function ($http) {
  75. return {
  76. init: function () {
  77. $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('cr_webapp_token');
  78. $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem('cr_webapp_token');
  79. }
  80. };
  81. })
  82. .run(function (api) {
  83. api.init();
  84. });