xzwebx-httpfilter 2.2.3 → 2.2.4

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.
Files changed (2) hide show
  1. package/HttpFilter.js +79 -82
  2. 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
- async function response(req, res, next) {
12
- let retData = {
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 MSG(params) {
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 CheckReq(req, res, next) {
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['interfaceInfo'] = ModuleInterfaceMap[module.id][subUri][req.method.toLowerCase()]
132
- res['interfaceInfo'] = ModuleInterfaceMap[module.id][subUri][req.method.toLowerCase()]
133
- let reqMsgId = ModuleInterfaceMap[module.id][subUri][req.method.toLowerCase()].reqMsgId
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,74 @@ 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.rspMsgId &&
107
+ params.codeKey == 'SUCC') {
108
+ let retMsgData = cycleCheckParams(FieldMap[this.interfaceInfo.rspMsgId], params.data)
109
+ if (retMsgData) {
110
+ params.codeKey = 'SVC_ERR'
111
+ params.msg = retMsgData
112
+ }
113
+ }
114
+ let code = ''
115
+ if (ResultCodeMap[params.codeKey]) {
116
+ code = ResultCodeMap[params.codeKey].rstCode
117
+ }
118
+
119
+ let msg = ''
120
+ if (!params.msg) {
121
+ if (TipsMap[params.codeKey]) {
122
+ msg = TipsMap[params.codeKey].tips
123
+ } else {
124
+ msg = ResultCodeMap[params.codeKey].codeDesc
125
+ }
126
+ } else {
127
+ if (typeof params.msg == 'string') {
128
+ msg = params.msg
129
+ }
130
+
131
+ if (typeof params.msg == 'object' && params.msg.length) {
132
+ if (TipsMap[params.msg[0]]) {
133
+ msg = TipsMap[params.msg[0]].tips
134
+ if (params.msg.length > 1) {
135
+ for (let i = 1; i < params.msg.length; i++) {
136
+ msg = Util.format(msg, params.msg[i])
137
+ }
138
+ }
139
+ } else {
140
+ msg = params.msg[0]
141
+ }
142
+ }
143
+ }
144
+
145
+ return this.send(
146
+ {
147
+ code: code,
148
+ msg: msg,
149
+ data: params.data
150
+ }
151
+ )
152
+ }
145
153
  function cycleCheckParams(msgFieldMap, data) {
146
154
  let retMsgData = null
147
155
 
@@ -525,15 +533,4 @@ function IsListOk(fCfgItem, paramValue) {
525
533
 
526
534
  return null
527
535
  }
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
- }
536
+ module.exports = Fun
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xzwebx-httpfilter",
3
- "version": "2.2.3",
3
+ "version": "2.2.4",
4
4
  "main": "HttpFilter.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"