初始化
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
module.exports = {
|
||||
path : "app/*/model/*.js",
|
||||
prefix : "auto",//接口前缀
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
'use strict';
|
||||
/**
|
||||
* 加载模型到路由
|
||||
* 加载app/api目录下的文件到路由
|
||||
*/
|
||||
const Router = require('koa-router')
|
||||
const config = require("./config")
|
||||
|
||||
// 错误处理
|
||||
module.exports = {
|
||||
sort : 999, //排序
|
||||
use : false, // 是否使用
|
||||
loadFun: async (app, fun) => { // 自行定义中间件的加载方式,将覆盖默认加载方法
|
||||
const router = await fun(app)
|
||||
app.use(router.routes()).use(router.allowedMethods())
|
||||
},
|
||||
fun : async (app) => {
|
||||
const router = new Router({ //设置前缀
|
||||
prefix: config.prefix
|
||||
});
|
||||
let list = await app.load(config.path)
|
||||
list.forEach(item => {
|
||||
|
||||
})
|
||||
return router
|
||||
}
|
||||
}
|
||||
@@ -58,9 +58,8 @@ module.exports = {
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
//默认根路由
|
||||
router.all('/', async (ctx, next) => {
|
||||
|
||||
ctx.body = app.res.success("ok")
|
||||
ctx.status = 200
|
||||
await next();
|
||||
|
||||
Reference in New Issue
Block a user