koa-combine-routers 可以使路由分模块,目录更加清晰,容易维护
app.js
const Koa = require('koa')
const router = require('./routes')
const app = new Koa()
app.use(router())
routes.js
const arouter = require("./a")
const brouter = require("./b")
const combineRouters = require('koa-combine-routers')
module.exports = combineRouters(arouter,brouter)
a.js
const Router= require('@koa/router')
const router=new Router()
router.get('/a',async ctx=>{
ctx.body='from a'
})
b.js
const Router= require('@koa/router')
const router=new Router()
router.get('/b',async ctx=>{
ctx.body='from b'
})
module.exports=router