koa

koa

router.get('/string', async (ctx, next) => {
  let a = await axios.get('http://localhost:1111/comments')  // 获取后端接口
  console.log('a',a);
  let obj = {
    'name': 'kang',
    'age': 24
  }
  ctx.body = a.data   // 提供给前端访问     http://xxx:3000/string
})

跨域

const cors = require('koa2-cors')   // 提供接口给前端,解决跨域
app.use(cors())  // 跨域

猜你喜欢

转载自www.cnblogs.com/gyz418/p/8984945.html
koa