前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >关于使用koa 跨域问题你可能会遇到

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

作者头像
马克社区
发布2022-06-15 10:48:41
2740
发布2022-06-15 10:48:41
举报
文章被收录于专栏:高端IT高端IT

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

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档