mas-server 3.0.41 → 3.0.42
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.
|
@@ -11,7 +11,7 @@ exports.default = (req, res, next) => {
|
|
|
11
11
|
if (routerObj) {
|
|
12
12
|
if (routerObj.methods != "all" &&
|
|
13
13
|
routerObj.methods != req.method.toLowerCase()) {
|
|
14
|
-
return res.return("error method!"
|
|
14
|
+
return res.return(null, 0, 400, "error method!");
|
|
15
15
|
}
|
|
16
16
|
if (routerObj.header && routerObj.header.length != 0) {
|
|
17
17
|
const headerObj = {};
|
|
@@ -19,18 +19,18 @@ exports.default = (req, res, next) => {
|
|
|
19
19
|
!item.optional && (headerObj[item.name] = item.type);
|
|
20
20
|
});
|
|
21
21
|
if (!(0, validType_1.default)(req.headers, headerObj)) {
|
|
22
|
-
return res.return("error headers format!"
|
|
22
|
+
return res.return(null, 0, 400, "error headers format!");
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
if (req.method == "GET" &&
|
|
26
26
|
routerObj.validFormat &&
|
|
27
27
|
!(0, validType_1.default)(req.query, routerObj.validFormat, !!routerObj.validFormatStrict)) {
|
|
28
|
-
return res.return("error data format!"
|
|
28
|
+
return res.return(null, 0, 400, "error data format!");
|
|
29
29
|
}
|
|
30
30
|
if (req.method == "POST" &&
|
|
31
31
|
routerObj.validFormat &&
|
|
32
32
|
!(0, validType_1.default)(req.body, routerObj.validFormat, !!routerObj.validFormatStrict)) {
|
|
33
|
-
return res.return("error data format!"
|
|
33
|
+
return res.return(null, 0, 400, "error data format!");
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
next();
|
package/dist/utils/validToken.js
CHANGED
|
@@ -9,11 +9,11 @@ exports.default = (req, res, next) => {
|
|
|
9
9
|
if ((0, masUtils_1.getType)(r === null || r === void 0 ? void 0 : r.permission) == "array") {
|
|
10
10
|
const token = req.headers[tokenConfig.headerParams];
|
|
11
11
|
if (!token) {
|
|
12
|
-
return res.return(
|
|
12
|
+
return res.return(null, 0, 400, "缺少重要参数");
|
|
13
13
|
}
|
|
14
14
|
let vt = (0, __1.validToken)({ token, permission: r.permission }, tokenConfig.pwd);
|
|
15
15
|
if (vt.status === 0) {
|
|
16
|
-
return res.return(vt.
|
|
16
|
+
return res.return(vt.errorCode, 0, 200, vt.msg);
|
|
17
17
|
}
|
|
18
18
|
res.token = vt;
|
|
19
19
|
next();
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@ export default (req: any, res: MasRes, next) => {
|
|
|
10
10
|
routerObj.methods != "all" &&
|
|
11
11
|
routerObj.methods != req.method.toLowerCase()
|
|
12
12
|
) {
|
|
13
|
-
return res.return("error method!"
|
|
13
|
+
return res.return(null, 0, 400, "error method!");
|
|
14
14
|
}
|
|
15
15
|
if (routerObj.header && routerObj.header.length != 0) {
|
|
16
16
|
const headerObj = {};
|
|
@@ -18,7 +18,7 @@ export default (req: any, res: MasRes, next) => {
|
|
|
18
18
|
!item.optional && (headerObj[item.name] = item.type);
|
|
19
19
|
});
|
|
20
20
|
if (!validType(req.headers, headerObj)) {
|
|
21
|
-
return res.return("error headers format!"
|
|
21
|
+
return res.return(null, 0, 400, "error headers format!");
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
if (
|
|
@@ -30,7 +30,7 @@ export default (req: any, res: MasRes, next) => {
|
|
|
30
30
|
!!routerObj.validFormatStrict
|
|
31
31
|
)
|
|
32
32
|
) {
|
|
33
|
-
return res.return("error data format!"
|
|
33
|
+
return res.return(null, 0, 400, "error data format!");
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
if (
|
|
@@ -38,7 +38,7 @@ export default (req: any, res: MasRes, next) => {
|
|
|
38
38
|
routerObj.validFormat &&
|
|
39
39
|
!validType(req.body, routerObj.validFormat, !!routerObj.validFormatStrict)
|
|
40
40
|
) {
|
|
41
|
-
return res.return("error data format!"
|
|
41
|
+
return res.return(null, 0, 400, "error data format!");
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
next();
|
package/src/utils/validToken.ts
CHANGED
|
@@ -8,11 +8,11 @@ export default (req: any, res: any, next) => {
|
|
|
8
8
|
if (getType(r?.permission) == "array") {
|
|
9
9
|
const token = req.headers[tokenConfig.headerParams];
|
|
10
10
|
if (!token) {
|
|
11
|
-
return res.return(
|
|
11
|
+
return res.return(null, 0, 400, "缺少重要参数");
|
|
12
12
|
}
|
|
13
13
|
let vt = validToken({ token, permission: r.permission }, tokenConfig.pwd);
|
|
14
14
|
if (vt.status === 0) {
|
|
15
|
-
return res.return(vt.
|
|
15
|
+
return res.return(vt.errorCode, 0, 200, vt.msg);
|
|
16
16
|
}
|
|
17
17
|
res.token = vt;
|
|
18
18
|
next();
|