@less-is-more/less-js 1.2.26 → 1.2.29
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 -10
package/package.json
CHANGED
package/src/router.js
CHANGED
|
@@ -37,9 +37,9 @@ module.exports = class Router {
|
|
|
37
37
|
console.log("start after action");
|
|
38
38
|
await targets.after(req, res, context);
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
const useTime = (new Date().getTime() - startTime) / 1000;
|
|
41
41
|
// controller方法有返回值的自动send
|
|
42
|
-
this._handleReturn(result, res);
|
|
42
|
+
this._handleReturn(result, useTime, req, res);
|
|
43
43
|
} catch (e) {
|
|
44
44
|
console.log(e);
|
|
45
45
|
return this._sendError(e.message ? e.message : "出错啦", res);
|
|
@@ -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
|
}
|
|
@@ -102,7 +108,7 @@ module.exports = class Router {
|
|
|
102
108
|
});
|
|
103
109
|
}
|
|
104
110
|
|
|
105
|
-
static _handleReturn(result, res) {
|
|
111
|
+
static _handleReturn(result, useTime, req, res) {
|
|
106
112
|
if (!Param.isBlank(result)) {
|
|
107
113
|
let content;
|
|
108
114
|
if (result instanceof Ret) {
|
|
@@ -111,14 +117,16 @@ module.exports = class Router {
|
|
|
111
117
|
if (typeof result === "string") {
|
|
112
118
|
content = result;
|
|
113
119
|
} else {
|
|
114
|
-
content =
|
|
120
|
+
content = JSON.stringify(result);
|
|
115
121
|
}
|
|
116
122
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
123
|
+
console.log(
|
|
124
|
+
req.headers["x-fc-request-id"],
|
|
125
|
+
useTime + "s",
|
|
126
|
+
req.path,
|
|
127
|
+
"response:",
|
|
128
|
+
content.length > 500 ? content.substring(0, 500) : content
|
|
129
|
+
);
|
|
122
130
|
res.send(content);
|
|
123
131
|
}
|
|
124
132
|
}
|