@less-is-more/less-js 1.4.27-1 → 1.4.27-11
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 +10 -14
package/package.json
CHANGED
package/src/router.js
CHANGED
|
@@ -13,34 +13,30 @@ module.exports = class Router {
|
|
|
13
13
|
* @param {object} targets 路由表。支持before和after,如果提供了会在执行主方法前后执行。需要async的方法。并且before返回值为Ret,如果不为true,会直接返回
|
|
14
14
|
* @param {*} event 事件载体
|
|
15
15
|
* @param {*} context 系统属性
|
|
16
|
-
* @param {*} callback 回调
|
|
17
16
|
* @returns 设置了useDefaultFormat为true,会返回错误信息
|
|
18
17
|
*/
|
|
19
|
-
static async routeEvent(targets, event, context
|
|
20
|
-
const eventObj = JSON.parse(event);
|
|
18
|
+
static async routeEvent(targets, event, context) {
|
|
19
|
+
const eventObj = JSON.parse(event.toString());
|
|
21
20
|
const req = {
|
|
22
21
|
path: eventObj.rawPath,
|
|
23
|
-
queries:
|
|
24
|
-
? {}
|
|
25
|
-
: qs.parse(eventObj.rawQueryString),
|
|
22
|
+
queries: eventObj.queryParameters,
|
|
26
23
|
headers: eventObj.headers,
|
|
27
24
|
body: eventObj.body,
|
|
28
25
|
isBase64Encoded: eventObj.isBase64Encoded,
|
|
29
26
|
};
|
|
30
27
|
let res = {
|
|
31
|
-
|
|
28
|
+
content: "",
|
|
29
|
+
send: function (content) {
|
|
32
30
|
this.content = content;
|
|
33
31
|
},
|
|
34
|
-
content: "",
|
|
35
32
|
};
|
|
36
33
|
// 转换后调用原来的方法
|
|
37
|
-
const result = this.route(targets, req, res, context);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
const result = await this.route(targets, req, res, context);
|
|
35
|
+
return {
|
|
36
|
+
statusCode: 200,
|
|
37
|
+
headers: Object.assign(result.headers || {}, event.resHeaders || {}),
|
|
38
|
+
body: res.content.startsWith("{") ? JSON.parse(res.content) : res.content,
|
|
41
39
|
};
|
|
42
|
-
|
|
43
|
-
callback(null, finalResponse);
|
|
44
40
|
}
|
|
45
41
|
|
|
46
42
|
/**
|