关于使用koa 跨域问题你可能会遇到
作者:互联网
var cors = require(‘koa2-cors’);
// 跨域
const allowOrigins = [
“http://localhost:8080” // 需要跨域的端口,与本服务器端口不一样,请注意。
];
app.use(cors({
origin: function(ctx) {
if (allowOrigins.includes(ctx.header.origin)) {
return ctx.header.origin;
}
return false;
},
exposeHeaders: [‘WWW-Authenticate’, ‘Server-Authorization’],
maxAge: 5,
credentials: true,
withCredentials:true,
allowMethods: [‘GET’, ‘POST’, ‘DELETE’],
allowHeaders: [‘Content-Type’, ‘Authorization’, ‘Accept’],
}));
更多内容请见原文,原文转载自:https://blog.csdn.net/weixin_44519496/article/details/119836163
标签:origin,return,跨域,遇到,koa,ctx,header,cors 来源: https://www.cnblogs.com/wangchuanxinshi/p/16353043.html