summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_shared/vue_resource_interceptor.js
blob: f1c1e553b1669108d151ae716bda0e313f6bdc5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* eslint-disable no-param-reassign, no-plusplus */
import Vue from 'vue';
import VueResource from 'vue-resource';

Vue.use(VueResource);

Vue.http.interceptors.push((request, next) => {
  Vue.activeResources = Vue.activeResources ? Vue.activeResources + 1 : 1;

  next(() => {
    Vue.activeResources--;
  });
});

Vue.http.interceptors.push((request, next) => {
  // needed in order to not break the tests.
  if ($.rails) {
    request.headers['X-CSRF-Token'] = $.rails.csrfToken();
  }
  next();
});