-
Notifications
You must be signed in to change notification settings - Fork 31
/
myRuleModule.js
48 lines (27 loc) · 1.14 KB
/
myRuleModule.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
40
41
42
43
44
45
46
47
48
const astHook = require("./astHook")
const handleCode = require("./handleCode")
module.exports = {
*beforeSendResponse(requestDetail, responseDetail) {
return astHook.astHook(requestDetail, responseDetail);
},
*beforeSendRequest(requestDetail){
if (typeof requestDetail.url == "string" && requestDetail.url.match("handleJsCode")){
let code = requestDetail.requestData.toString()
code = "(function tingHook(){"+code+"})(tingHook)"
try{
var newJsCode = handleCode.handleJsCode(code,true).replace("(function tingHook() {\n ","").replace("\n})(tingHook);","");
}catch(err){
console.log("请求解析失败",err,code)
return null
}
return {
response: {
statusCode: 200,
header: { 'content-type': 'text/plain; charset=utf-8' ,"access-control-allow-origin": "*"},
body: newJsCode
}
};
}
return null;
}
}