-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
89 lines (78 loc) · 2.84 KB
/
app.js
File metadata and controls
89 lines (78 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
var app = angular.module('socialNetwork', ['ngRoute', 'ngResource', 'ngCookies', 'ui.bootstrap', 'ngLetterAvatar']);
app.config(['$routeProvider', '$httpProvider', '$sceDelegateProvider', 'URL',
function ($routeProvider, $httpProvider, $sceDelegateProvider, URL) {
$httpProvider.interceptors.push('responseObserver');
$httpProvider.defaults.withCredentials = true;
$httpProvider.defaults.useXDomain = true;
$httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
// Fix AngularJS bug
$sceDelegateProvider.resourceUrlWhitelist([
'self',
'^(?:http(?:s)?:\/\/)?(?:[^\.]+\.)?\(google|facebook)\.com(/.*)?$',
URL + "**"
]);
$routeProvider
.when('/profile', {
templateUrl: 'partials/profile.html',
controller: 'profileController'
})
.when('/profile/:profileId', {
templateUrl: 'partials/profile.html',
controller: 'profileController'
})
.when('/users', {
templateUrl: 'partials/users.html',
controller: 'usersController'
})
.when('/messages', {
templateUrl: 'partials/messages.html',
controller: 'messagesController'
})
.when('/messages/:profileId', {
templateUrl: 'partials/dialog.html',
controller: 'dialogController'
})
.when('/friends', {
templateUrl: 'partials/users.html',
controller: 'friendsController'
})
.when('/settings', {
templateUrl: 'partials/settings.html',
controller: 'settingsController'
})
.when('/login', {
templateUrl: 'partials/login.html',
controller: 'loginController'
})
.when('/signUp', {
templateUrl: 'partials/signup.html',
controller: 'signUpController'
})
.otherwise(
{
redirectTo: '/profile'
}
)
;
}]);
app.factory('responseObserver', ['$rootScope', '$q', '$location', function ($rootScope, $q, $location) {
return {
'responseError': function (errorResponse) {
function handleLogin() {
if ($location.path() != "login" && $location.path() != "signUp") {
$rootScope.targetUrl = "#" + $location.path();
}
$location.path("/login");
}
switch (errorResponse.status) {
case 401: handleLogin(); break;
case 403: handleLogin(); break;
case 419: handleLogin(); break;
case 440: handleLogin(); break;
}
return $q.reject(errorResponse);
}
};
}]);
app.constant('URL', 'http://localhost:8080');
// app.constant('URL', 'https://social-network-spring.herokuapp.com');