ThinkJS 3.0 跨域中间件 @koa/cors 配置
安装 @koa/cors
ThinkJS 3.0 是基于 Koa 2 开发的 WEB 框架,一开始就考虑兼容 Koa 2 中间件。
npm install @koa/cors --save
更改配置
在 Middleware 中间件配置文件 middleware.js 中添加 cors 相关配置
const path = require('path');
// 引入 cors
const cors = require('@koa/cors');
const isDev = think.env === 'development';
module.exports = [
// 添加 cors
{
handle: cors,
options: {}
},
// 其它配置省略
}