forked from nettofarah/axios-vcr
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
37 lines (30 loc) · 1.02 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var RequestMiddleware = require('./lib/RequestMiddleware');
var ResponseMiddleware = require('./lib/ResponseMiddleware');
var cassettes = {}
function mountCassette(axios, cassettePath) {
var responseInterceptor = axios.interceptors.response.use(
ResponseMiddleware.success(cassettePath),
ResponseMiddleware.failure
);
var requestInterceptor = axios.interceptors.request.use(
RequestMiddleware.success(cassettePath),
RequestMiddleware.failure
);
cassettes[cassettePath] = {
responseInterceptor: responseInterceptor,
requestInterceptor: requestInterceptor,
axios: axios
};
}
function ejectCassette(cassettePath) {
var interceptors = cassettes[cassettePath];
var axios = interceptors.axios;
axios.interceptors.response.eject(interceptors.responseInterceptor);
axios.interceptors.request.eject(interceptors.requestInterceptor);
}
module.exports = {
mountCassette: mountCassette,
ejectCassette: ejectCassette,
RequestMiddleware: RequestMiddleware,
ResponseMiddleware: ResponseMiddleware
}