//在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