@less-is-more/less-js 1.2.25 → 1.2.28
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/router.js +18 -8
package/package.json
CHANGED
package/src/router.js
CHANGED
|
@@ -37,6 +37,7 @@ module.exports = class Router {
|
|
|
37
37
|
console.log("start after action");
|
|
38
38
|
await targets.after(req, res, context);
|
|
39
39
|
}
|
|
40
|
+
console.log("end", (new Date().getTime() - startTime) / 1000, "s");
|
|
40
41
|
// controller方法有返回值的自动send
|
|
41
42
|
this._handleReturn(result, res);
|
|
42
43
|
} catch (e) {
|
|
@@ -49,7 +50,6 @@ module.exports = class Router {
|
|
|
49
50
|
} else {
|
|
50
51
|
return this._sendError("请输入方法", res);
|
|
51
52
|
}
|
|
52
|
-
console.log("end", (new Date().getTime() - startTime) / 1000, "s");
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
static _getPath(req) {
|
|
@@ -80,7 +80,13 @@ module.exports = class Router {
|
|
|
80
80
|
req.body = querystring.parse(decodeURIComponent(data));
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
-
if (req.params == undefined)
|
|
83
|
+
if (req.params == undefined) {
|
|
84
|
+
req.params = {};
|
|
85
|
+
} else {
|
|
86
|
+
// express特有的 0为路径,处理一下
|
|
87
|
+
delete req.params[0];
|
|
88
|
+
}
|
|
89
|
+
|
|
84
90
|
if (!Param.isBlank(req.queries)) {
|
|
85
91
|
Object.keys(req.queries).forEach((n) => (req.params[n] = req.queries[n]));
|
|
86
92
|
}
|
|
@@ -104,18 +110,22 @@ module.exports = class Router {
|
|
|
104
110
|
|
|
105
111
|
static _handleReturn(result, res) {
|
|
106
112
|
if (!Param.isBlank(result)) {
|
|
113
|
+
let content;
|
|
107
114
|
if (result instanceof Ret) {
|
|
108
|
-
|
|
109
|
-
res.send(result.toString());
|
|
115
|
+
content = result.toString();
|
|
110
116
|
} else {
|
|
111
117
|
if (typeof result === "string") {
|
|
112
|
-
|
|
113
|
-
res.send(result);
|
|
118
|
+
content = result;
|
|
114
119
|
} else {
|
|
115
|
-
|
|
116
|
-
res.send(JSON.stringify(result));
|
|
120
|
+
content = JSON.stringify(result);
|
|
117
121
|
}
|
|
118
122
|
}
|
|
123
|
+
if (content.length > 500) {
|
|
124
|
+
console.log("return:", content.substring(0, 500));
|
|
125
|
+
} else {
|
|
126
|
+
console.log("return:", content);
|
|
127
|
+
}
|
|
128
|
+
res.send(content);
|
|
119
129
|
}
|
|
120
130
|
}
|
|
121
131
|
|