update packages
This commit is contained in:
33
src/route.ts
33
src/route.ts
@@ -17,6 +17,7 @@ export const addAuth = (app: App) => {
|
||||
.route({
|
||||
path: 'auth',
|
||||
id: 'auth',
|
||||
description: '验证token,必须成功, 错误返回401,正确赋值到ctx.state.tokenUser',
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const token = ctx.query.token;
|
||||
@@ -40,6 +41,7 @@ export const addAuth = (app: App) => {
|
||||
path: 'auth',
|
||||
key: 'can',
|
||||
id: 'auth-can',
|
||||
description: '验证token,可以不成功,错误不返回401,正确赋值到ctx.state.tokenUser,失败赋值null',
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
if (ctx.query?.token) {
|
||||
@@ -67,6 +69,7 @@ app
|
||||
id: 'auth-admin',
|
||||
isDebug: true,
|
||||
middleware: ['auth'],
|
||||
description: '验证token,必须是admin用户, 错误返回403,正确赋值到ctx.state.tokenAdmin',
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const tokenUser = ctx.state.tokenUser;
|
||||
@@ -140,18 +143,26 @@ app
|
||||
|
||||
app
|
||||
.route({
|
||||
path: 'test',
|
||||
key: 'test',
|
||||
path: 'router',
|
||||
key: 'list',
|
||||
description: '列出所有的当前的可请求的路由信息',
|
||||
middleware: ['auth-can']
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
ctx.body = app.router.routes.map((item) => {
|
||||
return {
|
||||
path: item.path,
|
||||
key: item.key,
|
||||
description: item.description,
|
||||
validator: item.validator,
|
||||
// schema: item.schema,
|
||||
};
|
||||
});
|
||||
const tokenUser = ctx.state.tokenUser;
|
||||
let isUser = !!tokenUser;
|
||||
ctx.body = {
|
||||
list: app.router.routes.map((item) => {
|
||||
return {
|
||||
id: item.id,
|
||||
path: item.path,
|
||||
key: item.key,
|
||||
description: item.description,
|
||||
middeleware: item.middleware,
|
||||
metadata: item.metadata,
|
||||
};
|
||||
}),
|
||||
isUser
|
||||
}
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
Reference in New Issue
Block a user