@kevisual/router 0.1.4 → 0.1.6
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/app.d.ts +5 -0
- package/dist/app.js +20208 -0
- package/dist/commander.d.ts +822 -0
- package/dist/commander.js +16401 -0
- package/dist/opencode.d.ts +816 -0
- package/dist/opencode.js +15308 -0
- package/dist/router-browser.d.ts +681 -0
- package/dist/router-browser.js +33416 -0
- package/dist/router-define.d.ts +565 -0
- package/dist/router-define.js +135 -0
- package/dist/router-simple.d.ts +110 -0
- package/dist/router-simple.js +708 -0
- package/dist/router.d.ts +1087 -0
- package/dist/router.js +19092 -0
- package/dist/ws.d.ts +865 -0
- package/dist/ws.js +3041 -0
- package/package.json +1 -1
- package/src/route.ts +40 -1
package/package.json
CHANGED
package/src/route.ts
CHANGED
|
@@ -434,7 +434,7 @@ export class QueryRouter<T extends SimpleObject = SimpleObject> implements throw
|
|
|
434
434
|
console.error('=====debug====:', e);
|
|
435
435
|
console.error('=====debug====:[path:key]:', `${route.path}-${route.key}`);
|
|
436
436
|
}
|
|
437
|
-
if (e instanceof CustomError) {
|
|
437
|
+
if (e instanceof CustomError || e?.code) {
|
|
438
438
|
ctx.code = e.code;
|
|
439
439
|
ctx.message = e.message;
|
|
440
440
|
} else {
|
|
@@ -782,6 +782,45 @@ export class QueryRouterServer<C extends SimpleObject = SimpleObject> extends Qu
|
|
|
782
782
|
const { path, key, id } = api as any;
|
|
783
783
|
return this.run({ path, key, id, payload }, ctx);
|
|
784
784
|
}
|
|
785
|
+
/**
|
|
786
|
+
* 创建认证相关的中间件,默认是 auth, auth-admin, auth-can 三个中间件
|
|
787
|
+
* @param fun 认证函数,接收 RouteContext 和认证类型
|
|
788
|
+
*/
|
|
789
|
+
async createAuth(fun: (ctx: RouteContext<C>, type?: 'auth' | 'auth-admin' | 'auth-can') => any) {
|
|
790
|
+
this.route({
|
|
791
|
+
path: 'auth',
|
|
792
|
+
key: 'auth',
|
|
793
|
+
id: 'auth',
|
|
794
|
+
description: 'token验证',
|
|
795
|
+
}).define(async (ctx) => {
|
|
796
|
+
if (fun) {
|
|
797
|
+
await fun(ctx, 'auth');
|
|
798
|
+
}
|
|
799
|
+
}).addTo(this, { overwrite: false });
|
|
800
|
+
|
|
801
|
+
this.route({
|
|
802
|
+
path: 'auth-admin',
|
|
803
|
+
key: 'auth-admin',
|
|
804
|
+
id: 'auth-admin',
|
|
805
|
+
description: 'admin token验证',
|
|
806
|
+
middleware: ['auth']
|
|
807
|
+
}).define(async (ctx) => {
|
|
808
|
+
if (fun) {
|
|
809
|
+
await fun(ctx, 'auth-admin');
|
|
810
|
+
}
|
|
811
|
+
}).addTo(this, { overwrite: false });
|
|
812
|
+
|
|
813
|
+
this.route({
|
|
814
|
+
path: 'auth-can',
|
|
815
|
+
key: 'auth-can',
|
|
816
|
+
id: 'auth-can',
|
|
817
|
+
description: '权限验证'
|
|
818
|
+
}).define(async (ctx) => {
|
|
819
|
+
if (fun) {
|
|
820
|
+
await fun(ctx, 'auth-can');
|
|
821
|
+
}
|
|
822
|
+
}).addTo(this, { overwrite: false });
|
|
823
|
+
}
|
|
785
824
|
}
|
|
786
825
|
|
|
787
826
|
|