Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | 5x 5x 5x 5x 5x 5x 5x 5x 5x 20x 5x 5x 5x | const Router = require('koa-router')
const compose = require('koa-compose')
const auth = require('../auth')
const routers = require('../app/controller')
const config = require('../config/env')
const apiRouter = new Router({
prefix: config.baseApi,
})
apiRouter.get('/', async(ctx, next) => {
ctx.redirect('/user');
});
function initRoute() {
apiRouter.use('/auth', auth.routes(), auth.allowedMethods())
Object.keys(routers).forEach(name => {
// if (/(.*)\.(js$|coffee$)/.test(file)) {
// require(modelsPath + '/' + file);
// }
// with the ES6 import case
// const routes = requireDir('./routes') // fload load case index.js router/user.js router/logs.js
// export default async(router) => {
// return routes[name]['default'](router)
return apiRouter.use(`/${name}`, routers[name].routes(), routers[name].allowedMethods())
});
}
module.exports = function (app) {
initRoute()
app.use(compose([
apiRouter.routes(),
apiRouter.allowedMethods(),
]))
} |