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