forked from ~ulysseskao/xdashangular

Dennis Kao
2016-04-25 ce0f5117e5830ade396e88594accf66c20200c81
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
//= wrapped
//= require /angular/angular
//= require /angular/angular-resource
//= require_self
//= require_tree services
 
angular.module("grailsangular.core", ['ngResource'])
    .constant("contextPath", window.contextPath)
    .config(config);
 
function config($httpProvider) {
    $httpProvider.defaults.headers.common["X-Requested-With"] = "XMLHttpRequest";
    $httpProvider.interceptors.push(httpRequestInterceptor);
}
 
function httpRequestInterceptor(contextPath) {
    return {
        request: function (config) {
            if (!config.url.indexOf("/") == 0 && contextPath) {
                config.url = contextPath + "/" + config.url;
            }
            return config;
        }
    };
}