2017-03-17 17:30:32 +00:00
|
|
|
import Vue from 'vue';
|
|
|
|
import VueResource from 'vue-resource';
|
|
|
|
|
|
|
|
Vue.use(VueResource);
|
2017-01-27 22:24:08 +00:00
|
|
|
|
2017-03-17 19:09:29 +00:00
|
|
|
// Maintain a global counter for active requests
|
2017-05-17 18:25:13 +00:00
|
|
|
// see: spec/support/wait_for_requests.rb
|
2017-01-27 22:24:08 +00:00
|
|
|
Vue.http.interceptors.push((request, next) => {
|
2017-03-17 19:09:29 +00:00
|
|
|
window.activeVueResources = window.activeVueResources || 0;
|
|
|
|
window.activeVueResources += 1;
|
2017-01-27 22:24:08 +00:00
|
|
|
|
2017-03-17 17:30:32 +00:00
|
|
|
next(() => {
|
2017-03-17 19:09:29 +00:00
|
|
|
window.activeVueResources -= 1;
|
2017-01-27 22:24:08 +00:00
|
|
|
});
|
|
|
|
});
|
2017-02-05 17:36:52 +00:00
|
|
|
|
2017-03-17 19:09:29 +00:00
|
|
|
// Inject CSRF token so we don't break any tests.
|
2017-02-05 17:36:52 +00:00
|
|
|
Vue.http.interceptors.push((request, next) => {
|
|
|
|
if ($.rails) {
|
2017-03-17 19:09:29 +00:00
|
|
|
// eslint-disable-next-line no-param-reassign
|
2017-02-05 17:36:52 +00:00
|
|
|
request.headers['X-CSRF-Token'] = $.rails.csrfToken();
|
|
|
|
}
|
|
|
|
next();
|
|
|
|
});
|