summaryrefslogtreecommitdiffstats
path: root/app/app.config.js
blob: 952c2212c0eeb427174c6a52c3c9c85379427371 (plain)
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
(function () {
    'use strict';

    angular
        .module('dcaeApp')
        .factory('httpRequestInterceptor', function ($injector, $rootScope) {
            var httpRequestInterceptor = {
                request: function (config) {
                    // Send the user only for API requests
                    var userId = "";
                    if ($rootScope.baseURL.indexOf('localhost') !== -1) {
                        // if (config.url.indexOf($rootScope.baseURL) !== -1) {
                        config.headers = config.headers || {};
                        userId = 'ym903w';
                        // userId = $injector     .get('Sdc.Services.CookieService')     .getUserId();
                        var user = {
                            userId: userId
                        };
                        if (user) {
                            config.headers['USER_ID'] = user.userId;
                        }
                        // }
                    } else {
                        config.headers = config.headers || {};
                        var user = {
                            userId: window.userId
                        };
                        userId = window.userId;
                        // var user = {     userId: $rootScope.cookieUser }; userId =
                        // $rootScope.cookieUser;
                        if (user) {
                            config.headers['USER_ID'] = user.userId;
                            console.log('Your User is:', user.userId);
                        } else {
                            console.log('Error look on your grunt file you dont have a user set');
                        }

                    }
                    $rootScope.userId = userId;
                    return config;
                }
            };
            return httpRequestInterceptor;
        })
        .config(config);

    function config($httpProvider) {

        // Ask for cross domain from the sever (need to allow this in server).
        $httpProvider.defaults.useXDomain = true;
        delete $httpProvider.defaults.headers.common['X-Requested-With'];

        $httpProvider
            .interceptors
            .push('httpRequestInterceptor');

        // HTTP Interceptor definition
        /*$httpProvider.interceptors.push('httpRequestInterceptor');
        $httpProvider.interceptors.push('httpResponseInterceptor');
        $httpProvider.interceptors.push('httpRequestErrorInterceptor');
        $httpProvider.interceptors.push('httpResponseErrorInterceptor');*/

    }

})();