koa 允许跨域

mac2022-06-30  20

1.安装模块

npm install koa2-cors --save

2.引用

const cors = require('koa2-cors'); ... // 允许跨域访问 app.use(cors({ exposeHeaders: ['WWW-Authenticate', 'Server-Authorization', 'Date'], maxAge: 100, credentials: true, allowMethods: ['GET', 'POST', 'OPTIONS'], allowHeaders: ['Content-Type', 'Authorization', 'Accept', 'X-Custom-Header', 'anonymous'], }));

.

转载于:https://www.cnblogs.com/crazycode2/p/11100298.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)