@less-is-more/less-js 1.4.18 → 1.4.20
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/package.json +1 -1
- package/src/param.js +1 -1
- package/src/router.js +13 -12
package/package.json
CHANGED
package/src/param.js
CHANGED
package/src/router.js
CHANGED
|
@@ -18,9 +18,9 @@ module.exports = class Router {
|
|
|
18
18
|
*/
|
|
19
19
|
static async route(targets, req, res, context) {
|
|
20
20
|
const startTime = new Date().getTime();
|
|
21
|
+
const { methodName, className } = this._getPath(req);
|
|
21
22
|
// 兼容非阿里云
|
|
22
23
|
await this._handleParams(req);
|
|
23
|
-
const { methodName, className } = this._getPath(req);
|
|
24
24
|
if (methodName) {
|
|
25
25
|
const controller = targets[className];
|
|
26
26
|
if (controller == undefined) {
|
|
@@ -49,7 +49,11 @@ module.exports = class Router {
|
|
|
49
49
|
// controller方法有返回值的自动send
|
|
50
50
|
this._handleReturn(result, startTime, req, res);
|
|
51
51
|
} catch (e) {
|
|
52
|
-
|
|
52
|
+
if (e instanceof Error) {
|
|
53
|
+
return this._sendError(e.message ? e.message : "出错啦", res, true);
|
|
54
|
+
} else {
|
|
55
|
+
return this._sendError(e, res, false);
|
|
56
|
+
}
|
|
53
57
|
}
|
|
54
58
|
} else {
|
|
55
59
|
return this._sendError("请输入正确方法", res);
|
|
@@ -60,13 +64,7 @@ module.exports = class Router {
|
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
static _getPath(req) {
|
|
63
|
-
console.log(
|
|
64
|
-
"path:",
|
|
65
|
-
req.method,
|
|
66
|
-
req.path,
|
|
67
|
-
req.headers["content-type"],
|
|
68
|
-
JSON.stringify(req.params)
|
|
69
|
-
);
|
|
67
|
+
console.log("path:", req.method, req.path, req.headers["content-type"]);
|
|
70
68
|
const paths = req.path.split("/");
|
|
71
69
|
const className = paths.length > 2 ? "/" + paths[paths.length - 2] : "/";
|
|
72
70
|
const methodName = paths[paths.length - 1];
|
|
@@ -77,7 +75,10 @@ module.exports = class Router {
|
|
|
77
75
|
if (req.query) {
|
|
78
76
|
req.queries = req.query;
|
|
79
77
|
}
|
|
80
|
-
console.log(
|
|
78
|
+
console.log(
|
|
79
|
+
"queries:",
|
|
80
|
+
req.queries ? JSON.stringify(req.queries).substring(0, 500) : ""
|
|
81
|
+
);
|
|
81
82
|
const isFile =
|
|
82
83
|
req.headers &&
|
|
83
84
|
req.headers["content-type"] &&
|
|
@@ -104,7 +105,7 @@ module.exports = class Router {
|
|
|
104
105
|
}
|
|
105
106
|
} else {
|
|
106
107
|
const data = await promisify(body)(req);
|
|
107
|
-
console.log("body: " + data);
|
|
108
|
+
console.log("body: " + data.substring(0, 500));
|
|
108
109
|
req.body = qs.parse(data);
|
|
109
110
|
}
|
|
110
111
|
}
|
|
@@ -153,7 +154,7 @@ module.exports = class Router {
|
|
|
153
154
|
useTime + "s",
|
|
154
155
|
req.path,
|
|
155
156
|
"response:",
|
|
156
|
-
content.
|
|
157
|
+
content.substring(0, 500)
|
|
157
158
|
);
|
|
158
159
|
res.send(content);
|
|
159
160
|
}
|