summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_shared/vue_resource_interceptor.js
blob: d3229f9f73002d45c116dee27760ce907907c336 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/* eslint-disable func-names, prefer-arrow-callback, no-unused-vars,
no-param-reassign, no-plusplus */
/* global Vue */

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

  next((response) => {
    if (typeof response.data === 'string') {
      response.data = JSON.parse(response.data);
    }

    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();
});