将路由拆分到另一个文件夹,并将其通过module暴露出去
const router = require("koa-router")()
router.get("/",(ctx)=>{
ctx.body = "hello world"
})
router.get("/my",async ctx=>{
ctx.body = "my"
})
router.get("/friend", async ctx=>{
ctx.body = 'f'
})
module.exports = router
在主页面接收router
const koa = require("koa")
const router = require('./routers')
const app = new koa()
app.use(router.routes())
app.listen(4000,()=>{
console.log('服务器开启了');
})