@kevisual/router 0.0.22 → 0.0.23
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.d.ts +10 -3
- package/dist/router-browser.js +17439 -530
- package/dist/router-sign.d.ts +1 -0
- package/dist/router-sign.js +15 -7
- package/dist/router.d.ts +8 -2
- package/dist/router.js +17446 -533
- package/package.json +11 -8
- package/src/app-browser.ts +5 -0
- package/src/app.ts +6 -0
- package/src/browser.ts +3 -1
- package/src/route.ts +8 -3
- package/src/sign.ts +22 -9
- package/src/test/static.ts +22 -0
- package/src/utils/is-engine.ts +15 -0
- package/src/validator/index.ts +2 -1
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.23",
|
|
5
5
|
"description": "",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/router.js",
|
|
@@ -21,19 +21,21 @@
|
|
|
21
21
|
"author": "abearxiong",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@kevisual/
|
|
24
|
+
"@kevisual/local-proxy": "^0.0.3",
|
|
25
|
+
"@kevisual/query": "^0.0.29",
|
|
25
26
|
"@rollup/plugin-alias": "^5.1.1",
|
|
26
|
-
"@rollup/plugin-commonjs": "^28.0.
|
|
27
|
+
"@rollup/plugin-commonjs": "^28.0.6",
|
|
27
28
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
28
|
-
"@rollup/plugin-typescript": "^12.1.
|
|
29
|
+
"@rollup/plugin-typescript": "^12.1.3",
|
|
29
30
|
"@types/lodash-es": "^4.17.12",
|
|
30
|
-
"@types/node": "^
|
|
31
|
+
"@types/node": "^24.0.3",
|
|
32
|
+
"@types/send": "^0.17.5",
|
|
31
33
|
"@types/ws": "^8.18.1",
|
|
32
34
|
"@types/xml2js": "^0.4.14",
|
|
33
35
|
"cookie": "^1.0.2",
|
|
34
36
|
"lodash-es": "^4.17.21",
|
|
35
37
|
"nanoid": "^5.1.5",
|
|
36
|
-
"rollup": "^4.
|
|
38
|
+
"rollup": "^4.44.0",
|
|
37
39
|
"rollup-plugin-dts": "^6.2.1",
|
|
38
40
|
"ts-loader": "^9.5.2",
|
|
39
41
|
"ts-node": "^10.9.2",
|
|
@@ -41,7 +43,7 @@
|
|
|
41
43
|
"typescript": "^5.8.3",
|
|
42
44
|
"ws": "npm:@kevisual/ws",
|
|
43
45
|
"xml2js": "^0.6.2",
|
|
44
|
-
"zod": "^3.25.
|
|
46
|
+
"zod": "^3.25.67"
|
|
45
47
|
},
|
|
46
48
|
"repository": {
|
|
47
49
|
"type": "git",
|
|
@@ -49,7 +51,8 @@
|
|
|
49
51
|
},
|
|
50
52
|
"dependencies": {
|
|
51
53
|
"path-to-regexp": "^8.2.0",
|
|
52
|
-
"selfsigned": "^2.4.1"
|
|
54
|
+
"selfsigned": "^2.4.1",
|
|
55
|
+
"send": "^1.2.0"
|
|
53
56
|
},
|
|
54
57
|
"publishConfig": {
|
|
55
58
|
"access": "public"
|
package/src/app.ts
CHANGED
|
@@ -105,6 +105,12 @@ export class App<T = {}, U = AppReqRes> {
|
|
|
105
105
|
static handleRequest(req: IncomingMessage, res: ServerResponse) {
|
|
106
106
|
return handleServer(req, res);
|
|
107
107
|
}
|
|
108
|
+
onServerRequest(fn: (req: IncomingMessage, res: ServerResponse) => void) {
|
|
109
|
+
if (!this.server) {
|
|
110
|
+
throw new Error('Server is not initialized');
|
|
111
|
+
}
|
|
112
|
+
this.server.on(fn);
|
|
113
|
+
}
|
|
108
114
|
}
|
|
109
115
|
|
|
110
116
|
export * from './browser.ts';
|
package/src/browser.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { Route, QueryRouter, QueryRouterServer } from './route.ts';
|
|
2
2
|
|
|
3
|
-
export { Rule, Schema
|
|
3
|
+
export type { Rule, Schema } from './validator/index.ts';
|
|
4
|
+
|
|
5
|
+
export { createSchema } from './validator/index.ts';
|
|
4
6
|
|
|
5
7
|
export type { RouteContext, RouteOpts } from './route.ts';
|
|
6
8
|
|
package/src/route.ts
CHANGED
|
@@ -54,7 +54,7 @@ export type RouteContext<T = { code?: number }, S = any> = {
|
|
|
54
54
|
queryRoute?: (message: { path: string; key?: string; payload?: any }, ctx?: RouteContext & { [key: string]: any }) => Promise<any>;
|
|
55
55
|
index?: number;
|
|
56
56
|
throw?: (code?: number | string, message?: string, tips?: string) => void;
|
|
57
|
-
/**
|
|
57
|
+
/** 是否需要序列化, 使用JSON.stringify和JSON.parse */
|
|
58
58
|
needSerialize?: boolean;
|
|
59
59
|
} & T;
|
|
60
60
|
export type SimpleObject = Record<string, any>;
|
|
@@ -603,7 +603,12 @@ export class QueryRouter {
|
|
|
603
603
|
message: res.message,
|
|
604
604
|
};
|
|
605
605
|
}
|
|
606
|
-
|
|
606
|
+
/**
|
|
607
|
+
* 设置上下文
|
|
608
|
+
* @description 这里的上下文是为了在handle函数中使用
|
|
609
|
+
* @param ctx
|
|
610
|
+
*/
|
|
611
|
+
setContext(ctx: RouteContext) {
|
|
607
612
|
this.context = ctx;
|
|
608
613
|
}
|
|
609
614
|
getList(): RouteInfo[] {
|
|
@@ -647,7 +652,7 @@ export class QueryRouter {
|
|
|
647
652
|
throw(...args: any[]) {
|
|
648
653
|
throw new CustomError(...args);
|
|
649
654
|
}
|
|
650
|
-
hasRoute(path: string, key
|
|
655
|
+
hasRoute(path: string, key: string = '') {
|
|
651
656
|
return this.routes.find((r) => r.path === path && r.key === key);
|
|
652
657
|
}
|
|
653
658
|
}
|
package/src/sign.ts
CHANGED
|
@@ -1,28 +1,33 @@
|
|
|
1
1
|
import { generate } from 'selfsigned';
|
|
2
2
|
|
|
3
|
-
type Attributes = {
|
|
3
|
+
export type Attributes = {
|
|
4
4
|
name: string;
|
|
5
5
|
value: string;
|
|
6
6
|
};
|
|
7
|
-
type AltNames = {
|
|
7
|
+
export type AltNames = {
|
|
8
8
|
type: number;
|
|
9
9
|
value?: string;
|
|
10
10
|
ip?: string;
|
|
11
11
|
};
|
|
12
12
|
export const createCert = (attrs: Attributes[] = [], altNames: AltNames[] = []) => {
|
|
13
13
|
let attributes = [
|
|
14
|
-
{ name: 'commonName', value: '*' }, // 通配符域名
|
|
15
14
|
{ name: 'countryName', value: 'CN' }, // 国家代码
|
|
16
15
|
{ name: 'stateOrProvinceName', value: 'ZheJiang' }, // 州名
|
|
17
|
-
{ name: 'localityName', value: '
|
|
18
|
-
{ name: 'organizationName', value: '
|
|
19
|
-
{ name: 'organizationalUnitName', value: '
|
|
16
|
+
{ name: 'localityName', value: 'HangZhou' }, // 城市名
|
|
17
|
+
{ name: 'organizationName', value: 'kevisual' }, // 组织名
|
|
18
|
+
{ name: 'organizationalUnitName', value: 'kevisual' }, // 组织单位
|
|
20
19
|
...attrs,
|
|
21
20
|
];
|
|
22
21
|
// attribute 根据name去重复, 后面的覆盖前面的
|
|
23
|
-
attributes =
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
attributes = Object.values(
|
|
23
|
+
attributes.reduce(
|
|
24
|
+
(acc, attr) => ({
|
|
25
|
+
...acc,
|
|
26
|
+
[attr.name]: attr,
|
|
27
|
+
}),
|
|
28
|
+
{} as Record<string, Attributes>,
|
|
29
|
+
),
|
|
30
|
+
);
|
|
26
31
|
|
|
27
32
|
const options = {
|
|
28
33
|
days: 365, // 证书有效期(天)
|
|
@@ -32,6 +37,14 @@ export const createCert = (attrs: Attributes[] = [], altNames: AltNames[] = [])
|
|
|
32
37
|
altNames: [
|
|
33
38
|
{ type: 2, value: '*' }, // DNS 名称
|
|
34
39
|
{ type: 2, value: 'localhost' }, // DNS
|
|
40
|
+
{
|
|
41
|
+
type: 2,
|
|
42
|
+
value: '[::1]',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: 7,
|
|
46
|
+
ip: 'fe80::1',
|
|
47
|
+
},
|
|
35
48
|
{ type: 7, ip: '127.0.0.1' }, // IP 地址
|
|
36
49
|
...altNames,
|
|
37
50
|
],
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { proxyRoute, initProxy } from '@kevisual/local-proxy/proxy.ts';
|
|
2
|
+
initProxy({
|
|
3
|
+
pagesDir: './demo',
|
|
4
|
+
watch: true,
|
|
5
|
+
});
|
|
6
|
+
import { App } from '../app.ts';
|
|
7
|
+
|
|
8
|
+
const app = new App();
|
|
9
|
+
app
|
|
10
|
+
.route({
|
|
11
|
+
path: 'a',
|
|
12
|
+
})
|
|
13
|
+
.define(async (ctx) => {
|
|
14
|
+
ctx.body = '1';
|
|
15
|
+
})
|
|
16
|
+
.addTo(app);
|
|
17
|
+
|
|
18
|
+
app.listen(2233, () => {
|
|
19
|
+
console.log('Server is running on http://localhost:2233');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
app.onServerRequest(proxyRoute);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
|
|
2
|
+
export const isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined' && typeof document.createElement === 'function';
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
export const isDeno = typeof Deno !== 'undefined' && typeof Deno.version === 'object' && typeof Deno.version.deno === 'string';
|
|
5
|
+
|
|
6
|
+
export const getEngine = () => {
|
|
7
|
+
if (isNode) {
|
|
8
|
+
return 'node';
|
|
9
|
+
} else if (isBrowser) {
|
|
10
|
+
return 'browser';
|
|
11
|
+
} else if (isDeno) {
|
|
12
|
+
return 'deno';
|
|
13
|
+
}
|
|
14
|
+
return 'unknown';
|
|
15
|
+
};
|
package/src/validator/index.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type { Rule, Schema } from './rule.ts';
|
|
2
|
+
export { schemaFormRule, createSchema, createSchemaList } from './rule.ts';
|