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.

90 lines
2.2 KiB

  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.travel',
  20. 'app.newTravel'
  21. ]).
  22. config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) {
  23. $locationProvider.hashPrefix('!');
  24. //$routeProvider.otherwise({redirectTo: '/main'});
  25. if((localStorage.getItem('cr_webapp_token')))
  26. {
  27. console.log(window.location.hash);
  28. if((window.location.hash==='#!/login')||(window.location.hash==='#!/signup'))
  29. {
  30. window.location='#!/main';
  31. }
  32. $routeProvider.otherwise({redirectTo: '/main'});
  33. }else{
  34. if((window.location!=='#!/login')||(window.location!=='#!/signup'))
  35. {
  36. console.log('app, user no logged');
  37. localStorage.removeItem('cr_webapp_token');
  38. localStorage.removeItem('cr_webapp_userdata');
  39. window.location='#!/login';
  40. $routeProvider.otherwise({redirectTo: '/login'});
  41. }
  42. }
  43. }])
  44. .config(function(toastrConfig) {
  45. angular.extend(toastrConfig, {
  46. autoDismiss: false,
  47. containerId: 'toast-container',
  48. maxOpened: 0,
  49. newestOnTop: true,
  50. positionClass: 'toast-bottom-right',
  51. preventDuplicates: false,
  52. preventOpenDuplicates: false,
  53. target: 'body'
  54. });
  55. })
  56. .factory('httpInterceptor', function httpInterceptor () {
  57. return {
  58. request: function(config) {
  59. return config;
  60. },
  61. requestError: function(config) {
  62. return config;
  63. },
  64. response: function(res) {
  65. return res;
  66. },
  67. responseError: function(res) {
  68. return res;
  69. }
  70. };
  71. })
  72. .factory('api', function ($http) {
  73. return {
  74. init: function () {
  75. $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('cr_webapp_token');
  76. $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem('cr_webapp_token');
  77. }
  78. };
  79. })
  80. .run(function (api) {
  81. api.init();
  82. });