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'],
}));

.

相关文章:

  • 2022-12-23
  • 2022-02-07
  • 2021-06-19
  • 2021-11-06
  • 2021-08-13
  • 2021-11-14
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-08
  • 2022-02-24
  • 2021-09-27
  • 2021-08-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案