Add Vue resource interceptor to performance bar
This commit is contained in:
parent
40c338a4bb
commit
fc32b57384
|
@ -1,11 +1,29 @@
|
||||||
|
import Vue from 'vue';
|
||||||
|
import _ from 'underscore';
|
||||||
import axios from '../../lib/utils/axios_utils';
|
import axios from '../../lib/utils/axios_utils';
|
||||||
|
|
||||||
|
let vueResourceInterceptor;
|
||||||
|
|
||||||
export default class PerformanceBarService {
|
export default class PerformanceBarService {
|
||||||
static fetchRequestDetails(peekUrl, requestId) {
|
static fetchRequestDetails(peekUrl, requestId) {
|
||||||
return axios.get(peekUrl, { params: { request_id: requestId } });
|
return axios.get(peekUrl, { params: { request_id: requestId } });
|
||||||
}
|
}
|
||||||
|
|
||||||
static registerInterceptor(peekUrl, callback) {
|
static registerInterceptor(peekUrl, callback) {
|
||||||
|
vueResourceInterceptor = (request, next) => {
|
||||||
|
next(response => {
|
||||||
|
const requestId = response.headers['x-request-id'];
|
||||||
|
const requestUrl = response.url;
|
||||||
|
console.log(requestUrl);
|
||||||
|
|
||||||
|
if (requestUrl !== peekUrl && requestId) {
|
||||||
|
callback(requestId, requestUrl);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Vue.http.interceptors.push(vueResourceInterceptor);
|
||||||
|
|
||||||
return axios.interceptors.response.use(response => {
|
return axios.interceptors.response.use(response => {
|
||||||
const requestId = response.headers['x-request-id'];
|
const requestId = response.headers['x-request-id'];
|
||||||
const requestUrl = response.config.url;
|
const requestUrl = response.config.url;
|
||||||
|
@ -20,5 +38,9 @@ export default class PerformanceBarService {
|
||||||
|
|
||||||
static removeInterceptor(interceptor) {
|
static removeInterceptor(interceptor) {
|
||||||
axios.interceptors.response.eject(interceptor);
|
axios.interceptors.response.eject(interceptor);
|
||||||
|
Vue.http.interceptors = _.without(
|
||||||
|
Vue.http.interceptors,
|
||||||
|
vueResourceInterceptor,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,10 @@
|
||||||
line-height: $performance-bar-height;
|
line-height: $performance-bar-height;
|
||||||
color: $perf-bar-text;
|
color: $perf-bar-text;
|
||||||
|
|
||||||
|
select {
|
||||||
|
width: 200px;
|
||||||
|
}
|
||||||
|
|
||||||
&.disabled {
|
&.disabled {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue