diff options
Diffstat (limited to 'app/assets/javascripts/vue_shared/vue_resource_interceptor.js')
-rw-r--r-- | app/assets/javascripts/vue_shared/vue_resource_interceptor.js | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/app/assets/javascripts/vue_shared/vue_resource_interceptor.js b/app/assets/javascripts/vue_shared/vue_resource_interceptor.js index f1c1e553b16..d5f87588c28 100644 --- a/app/assets/javascripts/vue_shared/vue_resource_interceptor.js +++ b/app/assets/javascripts/vue_shared/vue_resource_interceptor.js @@ -1,20 +1,23 @@ -/* eslint-disable no-param-reassign, no-plusplus */ import Vue from 'vue'; import VueResource from 'vue-resource'; Vue.use(VueResource); +// Maintain a global counter for active requests +// see: spec/support/wait_for_vue_resource.rb Vue.http.interceptors.push((request, next) => { - Vue.activeResources = Vue.activeResources ? Vue.activeResources + 1 : 1; + window.activeVueResources = window.activeVueResources || 0; + window.activeVueResources += 1; next(() => { - Vue.activeResources--; + window.activeVueResources -= 1; }); }); +// Inject CSRF token so we don't break any tests. Vue.http.interceptors.push((request, next) => { - // needed in order to not break the tests. if ($.rails) { + // eslint-disable-next-line no-param-reassign request.headers['X-CSRF-Token'] = $.rails.csrfToken(); } next(); |