关于使用koa 跨域问题你可能会遇到

2022-06-15 10:48:41 浏览数 (1)

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

0 人点赞