简略介绍
egg-router-auth
基于 apidoc 来构建参数校验
性能
- 在egg我的项目中验证路由表中是否蕴含申请的url,如果申请了路由表中未存在的路由,则会提醒相应信息
- 在egg我的项目中验证在许可的路由中是否存在用户的jwt登录
- 验证路由的参数
装置
npm i egg-router-auth --save
配置相干
文件目录配置
倡议文件目录需按此配置
project├── app│ ├── controller│ │ └── home.js│ └── router.js├── apidoc│ └── output| └── api_data.json│ └── template| └── api_data.json||...
开启插件
// config/plugin.jsexports.auth = { enable: true, package: 'egg-router-auth',};
配置
// config/config.default.jsconfig.auth = { jwtExclude: ['/api/login', '/api/public/verification'], // 验证用户登录须要跳过的路由 errorCode: -2, // 谬误的code, output: 'apidoc/output', // apidoc输入目录,必选 template: 'apidoc/template' // apidoc模板,可选}
应用
// app/controller/home.js /** * @api {GET} /api/test 一般测试接口 * @apiParam {string} user 用户名 */ async test() { const { ctx } = this; const res = '测试'; ctx.body = res; } /** * @api {GET} /api/test 多参数类型测试接口 * @apiParam {string|null} user 用户名 */ async test1() { const { ctx } = this; const res = '测试'; ctx.body = res; } /** * @api {GET} /api/test 可选参数测试接口 * @apiParam {string} [user] 用户名 */ async test2() { const { ctx } = this; const res = '测试'; ctx.body = res; } /** * @api {GET} /api/test 简单类型测试接口 * @apiParam {object} user 用户 * @apiParam {string} user.name 用户名 */ async test3() { const { ctx } = this; const res = '测试'; ctx.body = res; }
发问交换
请到 egg-router-auth issues 异步交换。