xzwebx-httpfilter 2.2.3 → 2.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HttpFilter.js +80 -82
- package/package.json +1 -1
package/HttpFilter.js
CHANGED
|
@@ -8,77 +8,15 @@ let ModuleMap = {}
|
|
|
8
8
|
let ModuleInterfaceMap = {}
|
|
9
9
|
let FieldMap = {}
|
|
10
10
|
let IsCheckedRes = true
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
codeKey: 'SUCC',
|
|
14
|
-
data: []
|
|
15
|
-
}
|
|
16
|
-
return res.Msg(retData)
|
|
17
|
-
}
|
|
18
|
-
function SetIsCheckedRes(isCheckedRes) {
|
|
19
|
-
if (isCheckedRes) {
|
|
20
|
-
IsCheckedRes = true
|
|
21
|
-
} else {
|
|
22
|
-
IsCheckedRes = false
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function Init(language, resultCodeMap, tipsMap, moduleMap, moduleInterfaceMap, fieldMap) {
|
|
11
|
+
let Fun = {}
|
|
12
|
+
Fun.Init = function(language, resultCodeMap, tipsMap, moduleMap, moduleInterfaceMap, fieldMap) {
|
|
26
13
|
ResultCodeMap = resultCodeMap
|
|
27
14
|
TipsMap = tipsMap[language] || {}
|
|
28
15
|
ModuleMap = moduleMap
|
|
29
16
|
ModuleInterfaceMap = moduleInterfaceMap
|
|
30
17
|
FieldMap = fieldMap
|
|
31
18
|
}
|
|
32
|
-
function
|
|
33
|
-
if (IsCheckedRes &&
|
|
34
|
-
this.interfaceInfo.rspMsgId &&
|
|
35
|
-
params.codeKey == 'SUCC') {
|
|
36
|
-
let retMsgData = cycleCheckParams(FieldMap[this.interfaceInfo.rspMsgId], params.data)
|
|
37
|
-
if (retMsgData) {
|
|
38
|
-
params.codeKey = 'SVC_ERR'
|
|
39
|
-
params.msg = retMsgData
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
let code = ''
|
|
43
|
-
if (ResultCodeMap[params.codeKey]) {
|
|
44
|
-
code = ResultCodeMap[params.codeKey].rstCode
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
let msg = ''
|
|
48
|
-
if (!params.msg) {
|
|
49
|
-
if (TipsMap[params.codeKey]) {
|
|
50
|
-
msg = TipsMap[params.codeKey].tips
|
|
51
|
-
} else {
|
|
52
|
-
msg = ResultCodeMap[params.codeKey].codeDesc
|
|
53
|
-
}
|
|
54
|
-
} else {
|
|
55
|
-
if (typeof params.msg == 'string') {
|
|
56
|
-
msg = params.msg
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (typeof params.msg == 'object' && params.msg.length) {
|
|
60
|
-
if (TipsMap[params.msg[0]]) {
|
|
61
|
-
msg = TipsMap[params.msg[0]].tips
|
|
62
|
-
if (params.msg.length > 1) {
|
|
63
|
-
for (let i = 1; i < params.msg.length; i++) {
|
|
64
|
-
msg = Util.format(msg, params.msg[i])
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
} else {
|
|
68
|
-
msg = params.msg[0]
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return this.send(
|
|
74
|
-
{
|
|
75
|
-
code: code,
|
|
76
|
-
msg: msg,
|
|
77
|
-
data: params.data
|
|
78
|
-
}
|
|
79
|
-
)
|
|
80
|
-
}
|
|
81
|
-
function SetRoutes(app, express, projectPath) {
|
|
19
|
+
Fun.SetRoutes = function(app, express, projectPath) {
|
|
82
20
|
for (let uri in ModuleMap) {
|
|
83
21
|
let module = ModuleMap[uri]
|
|
84
22
|
let router = express.Router()
|
|
@@ -103,8 +41,7 @@ function SetRoutes(app, express, projectPath) {
|
|
|
103
41
|
app.use(ModuleMap[uri].uri, router)
|
|
104
42
|
}
|
|
105
43
|
}
|
|
106
|
-
function
|
|
107
|
-
res.Msg = MSG
|
|
44
|
+
Fun.CheckUrl = function(req, res, next) {
|
|
108
45
|
const baseUrlList = req.url.split('/')
|
|
109
46
|
const subUri = baseUrlList[baseUrlList.length - 1]
|
|
110
47
|
let baseUrl = ''
|
|
@@ -128,9 +65,12 @@ function CheckReq(req, res, next) {
|
|
|
128
65
|
return res.Msg({codeKey: 'CLT_ERR', msg: ['WEBX_ERR_URL']})
|
|
129
66
|
}
|
|
130
67
|
|
|
131
|
-
req
|
|
132
|
-
res
|
|
133
|
-
|
|
68
|
+
req.interfaceInfo = ModuleInterfaceMap[module.id][subUri][req.method.toLowerCase()]
|
|
69
|
+
res.interfaceInfo = ModuleInterfaceMap[module.id][subUri][req.method.toLowerCase()]
|
|
70
|
+
return next()
|
|
71
|
+
}
|
|
72
|
+
Fun.CheckReq = function(req, res, next) {
|
|
73
|
+
let reqMsgId = req.interfaceInfo.reqMsgId
|
|
134
74
|
if (!reqMsgId) {
|
|
135
75
|
return next()
|
|
136
76
|
}
|
|
@@ -142,6 +82,75 @@ function CheckReq(req, res, next) {
|
|
|
142
82
|
|
|
143
83
|
return next()
|
|
144
84
|
}
|
|
85
|
+
Fun.SetMsg = function(req, res, next) {
|
|
86
|
+
res.Msg = MSG
|
|
87
|
+
return next()
|
|
88
|
+
}
|
|
89
|
+
Fun.SetIsCheckedRes = function(isCheckedRes) {
|
|
90
|
+
if (isCheckedRes) {
|
|
91
|
+
IsCheckedRes = true
|
|
92
|
+
} else {
|
|
93
|
+
IsCheckedRes = false
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function response(req, res, next) {
|
|
98
|
+
let retData = {
|
|
99
|
+
codeKey: 'SUCC',
|
|
100
|
+
data: []
|
|
101
|
+
}
|
|
102
|
+
return res.Msg(retData)
|
|
103
|
+
}
|
|
104
|
+
function MSG(params) {
|
|
105
|
+
if (IsCheckedRes &&
|
|
106
|
+
this.interfaceInfo &&
|
|
107
|
+
this.interfaceInfo.rspMsgId &&
|
|
108
|
+
params.codeKey == 'SUCC') {
|
|
109
|
+
let retMsgData = cycleCheckParams(FieldMap[this.interfaceInfo.rspMsgId], params.data)
|
|
110
|
+
if (retMsgData) {
|
|
111
|
+
params.codeKey = 'SVC_ERR'
|
|
112
|
+
params.msg = retMsgData
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
let code = ''
|
|
116
|
+
if (ResultCodeMap[params.codeKey]) {
|
|
117
|
+
code = ResultCodeMap[params.codeKey].rstCode
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
let msg = ''
|
|
121
|
+
if (!params.msg) {
|
|
122
|
+
if (TipsMap[params.codeKey]) {
|
|
123
|
+
msg = TipsMap[params.codeKey].tips
|
|
124
|
+
} else {
|
|
125
|
+
msg = ResultCodeMap[params.codeKey].codeDesc
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
if (typeof params.msg == 'string') {
|
|
129
|
+
msg = params.msg
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (typeof params.msg == 'object' && params.msg.length) {
|
|
133
|
+
if (TipsMap[params.msg[0]]) {
|
|
134
|
+
msg = TipsMap[params.msg[0]].tips
|
|
135
|
+
if (params.msg.length > 1) {
|
|
136
|
+
for (let i = 1; i < params.msg.length; i++) {
|
|
137
|
+
msg = Util.format(msg, params.msg[i])
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
} else {
|
|
141
|
+
msg = params.msg[0]
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return this.send(
|
|
147
|
+
{
|
|
148
|
+
code: code,
|
|
149
|
+
msg: msg,
|
|
150
|
+
data: params.data
|
|
151
|
+
}
|
|
152
|
+
)
|
|
153
|
+
}
|
|
145
154
|
function cycleCheckParams(msgFieldMap, data) {
|
|
146
155
|
let retMsgData = null
|
|
147
156
|
|
|
@@ -525,15 +534,4 @@ function IsListOk(fCfgItem, paramValue) {
|
|
|
525
534
|
|
|
526
535
|
return null
|
|
527
536
|
}
|
|
528
|
-
|
|
529
|
-
function SetMsg(req, res, next) {
|
|
530
|
-
res.Msg = MSG
|
|
531
|
-
return next()
|
|
532
|
-
}
|
|
533
|
-
module.exports = {
|
|
534
|
-
Init: Init,
|
|
535
|
-
SetRoutes: SetRoutes,
|
|
536
|
-
CheckReq: CheckReq,
|
|
537
|
-
SetMsg: SetMsg,
|
|
538
|
-
SetIsCheckedRes: SetIsCheckedRes
|
|
539
|
-
}
|
|
537
|
+
module.exports = Fun
|