@kevisual/router 0.0.7 → 0.0.8-alpha.1
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/dist/router-browser.js +2 -2
- package/dist/router-simple-lib.d.ts +3 -0
- package/dist/router-simple-lib.js +35 -0
- package/dist/router.js +3 -3
- package/package.json +7 -1
package/dist/router-browser.js
CHANGED
|
@@ -6016,7 +6016,7 @@ class QueryRouter {
|
|
|
6016
6016
|
ctx.body = null;
|
|
6017
6017
|
return ctx;
|
|
6018
6018
|
}
|
|
6019
|
-
ctx.query = ctx.nextQuery;
|
|
6019
|
+
ctx.query = { ...ctx.query, ...ctx.nextQuery };
|
|
6020
6020
|
ctx.nextQuery = {};
|
|
6021
6021
|
return await this.runRoute(path, key, ctx);
|
|
6022
6022
|
}
|
|
@@ -6043,7 +6043,7 @@ class QueryRouter {
|
|
|
6043
6043
|
*/
|
|
6044
6044
|
async parse(message, ctx) {
|
|
6045
6045
|
if (!message?.path) {
|
|
6046
|
-
return Promise.resolve({ code: 404, body: 'Not found path' });
|
|
6046
|
+
return Promise.resolve({ code: 404, body: null, message: 'Not found path' });
|
|
6047
6047
|
}
|
|
6048
6048
|
const { path, key = '', payload = {}, ...query } = message;
|
|
6049
6049
|
ctx = ctx || {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import xml2js from 'xml2js';
|
|
2
|
+
|
|
3
|
+
const parseXml = async (req) => {
|
|
4
|
+
return await new Promise((resolve) => {
|
|
5
|
+
// 读取请求数据
|
|
6
|
+
let data = '';
|
|
7
|
+
req.setEncoding('utf8');
|
|
8
|
+
// 监听data事件,接收数据片段
|
|
9
|
+
req.on('data', (chunk) => {
|
|
10
|
+
data += chunk;
|
|
11
|
+
});
|
|
12
|
+
// 当请求结束时处理数据
|
|
13
|
+
req.on('end', () => {
|
|
14
|
+
try {
|
|
15
|
+
// 使用xml2js解析XML
|
|
16
|
+
xml2js.parseString(data, function (err, result) {
|
|
17
|
+
if (err) {
|
|
18
|
+
console.error('XML解析错误:', err);
|
|
19
|
+
resolve(null);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
const jsonString = JSON.stringify(result);
|
|
23
|
+
resolve(jsonString);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
console.error('处理请求时出错:', error);
|
|
29
|
+
resolve(null);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { parseXml };
|
package/dist/router.js
CHANGED
|
@@ -6035,7 +6035,7 @@ class QueryRouter {
|
|
|
6035
6035
|
ctx.body = null;
|
|
6036
6036
|
return ctx;
|
|
6037
6037
|
}
|
|
6038
|
-
ctx.query = ctx.nextQuery;
|
|
6038
|
+
ctx.query = { ...ctx.query, ...ctx.nextQuery };
|
|
6039
6039
|
ctx.nextQuery = {};
|
|
6040
6040
|
return await this.runRoute(path, key, ctx);
|
|
6041
6041
|
}
|
|
@@ -6062,7 +6062,7 @@ class QueryRouter {
|
|
|
6062
6062
|
*/
|
|
6063
6063
|
async parse(message, ctx) {
|
|
6064
6064
|
if (!message?.path) {
|
|
6065
|
-
return Promise.resolve({ code: 404, body: 'Not found path' });
|
|
6065
|
+
return Promise.resolve({ code: 404, body: null, message: 'Not found path' });
|
|
6066
6066
|
}
|
|
6067
6067
|
const { path, key = '', payload = {}, ...query } = message;
|
|
6068
6068
|
ctx = ctx || {};
|
|
@@ -6319,7 +6319,7 @@ const handleServer = async (req, res) => {
|
|
|
6319
6319
|
const handle = createHandleCtx(req, res);
|
|
6320
6320
|
const cookies = handle.req.cookies;
|
|
6321
6321
|
if (!token) {
|
|
6322
|
-
token = cookies.token;
|
|
6322
|
+
token = cookies.token; // cookie优先
|
|
6323
6323
|
}
|
|
6324
6324
|
if (token) {
|
|
6325
6325
|
token = token.replace('Bearer ', '');
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@kevisual/router",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.8-alpha.1",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"@types/lodash-es": "^4.17.12",
|
|
27
27
|
"@types/node": "^22.13.4",
|
|
28
28
|
"@types/ws": "^8.5.14",
|
|
29
|
+
"@types/xml2js": "^0.4.14",
|
|
29
30
|
"cookie": "^1.0.2",
|
|
30
31
|
"lodash-es": "^4.17.21",
|
|
31
32
|
"nanoid": "^5.1.0",
|
|
@@ -35,6 +36,7 @@
|
|
|
35
36
|
"ts-node": "^10.9.2",
|
|
36
37
|
"tslib": "^2.8.1",
|
|
37
38
|
"typescript": "^5.7.3",
|
|
39
|
+
"xml2js": "^0.6.2",
|
|
38
40
|
"zod": "^3.24.2"
|
|
39
41
|
},
|
|
40
42
|
"repository": {
|
|
@@ -65,6 +67,10 @@
|
|
|
65
67
|
"./simple": {
|
|
66
68
|
"import": "./dist/router-simple.js",
|
|
67
69
|
"require": "./dist/router-simple.js"
|
|
70
|
+
},
|
|
71
|
+
"./simple-lib": {
|
|
72
|
+
"import": "./dist/router-simple-lib.js",
|
|
73
|
+
"require": "./dist/router-simple-lib.js"
|
|
68
74
|
}
|
|
69
75
|
}
|
|
70
76
|
}
|