//在server/interface/city.js
import Router from 'koa-router';
const router = new Router({
    prefix:'/city'    //给路由添加前缀
})
router.get('/list', async (ctx) => {
    ctx.body=['北京','天津']
})
export default router;


//在server/index.js
import cityInterface from './interface/city'
app.use(cityInterface.routes()).use(cityInterface.allowedMethods())   //固定写法

测试一下curl http://localhost:3000/city/list 或者浏览器输入http://localhost:3000/city/list

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。