Fork me on GitHub

koa2跨域

“koa2-cors”: “^2.0.5”,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const cors = require('koa2-cors');

app.use(cors({
origin: function(ctx) {
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'],
}));
显示 Gitment 评论