-
Notifications
You must be signed in to change notification settings - Fork 495
/
proxy.ts
52 lines (38 loc) · 1.26 KB
/
proxy.ts
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
40
41
42
43
44
45
46
47
48
import { proxy } from "../index"
import { testRequest } from './test'
export function testProxy() {
testRequest('https://cc/');
}
const { unProxy: unProxy1, originXhr: originXhr1 } = proxy({
onRequest: (config, handler) => {
console.log(`1. onRequest: ${config.url}`);
config.headers = { 'content-type': 'text/text', customHeader1: 'customHeader1', ...config.headers };
handler.next(config);
},
onError: (err, handler) => {
console.log(`1. onError: ${err.config.url}`);
handler.next(err);
},
onResponse: (response, handler) => {
console.log(`1. onResponse: ${response.config.url}`);
handler.next(response);
}
}, window);
// const { unProxy: unProxy2, originXhr: originXhr2 } = proxy({
// onRequest: (config, handler) => {
// console.log(`2. onRequest: ${config.url}`);
// config.headers = { 'content-type': 'text/text', customHeader2: 'customHeader2', ...config.headers };
// handler.next(config);
// },
// onError: (err, handler) => {
// console.log(`2. onError: ${err.config.url}`);
// handler.next(err);
// },
// onResponse: (response, handler) => {
// console.log(`2. onResponse: ${response.config.url}`);
// handler.next(response)
// }
// }, window);
// unProxy1();
// unProxy2();
testProxy()