-
Notifications
You must be signed in to change notification settings - Fork 23
/
index.js
39 lines (31 loc) · 1.06 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
38
39
const RequestMiddleware = require('./lib/RequestMiddleware');
const ResponseMiddleware = require('./lib/ResponseMiddleware');
const cassettes = {}
function mountCassette(cassettePath) {
const axios = require('axios');
let responseInterceptor = axios.interceptors.response.use(
ResponseMiddleware.success(cassettePath),
ResponseMiddleware.failure
);
let requestInterceptor = axios.interceptors.request.use(
RequestMiddleware.success(cassettePath),
RequestMiddleware.failure
);
cassettes[cassettePath] = {
responseInterceptor: responseInterceptor,
requestInterceptor: requestInterceptor,
axios: axios
};
}
function ejectCassette(cassettePath) {
let interceptors = cassettes[cassettePath];
let 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
}