[参考文档](https://www.jianshu.com/p/5b3acded5182)
~~~
//koa实现跨域
const koa = require('koa');
const app = new koa;
var cors = require('koa2-cors');
app.use(cors({
origin: function (ctx) {
//访问主域名下的test地址不允许跨域
if (ctx.url === '/test') {
return false;
}
return '*';
},
exposeHeaders: ['WWW-Authenticate', 'Server-Authorization'],
maxAge: 5,
credentials: true,
allowMethods: ['GET', 'POST', 'DELETE'],
allowHeaders: ['Content-Type', 'Authorization', 'Accept'],
}));
app.use(async ctx=>{
ctx.body = "hello world"
})
app.listen(8080)
~~~