在开发者工具network中能够看到字体文件的请求返回的是成功,但是console中输出了以下内容Font from origin 'http://127.0.0.1:3000' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.这是在服务中koa2-cors的配置app.use(cors({ origin: function (ctx) { return '*' }, exposeHeaders: ['WWW-Authenticate', 'Server-Authorization'], maxAge: 5, credentials: true, allowMethods: ['GET', 'POST', 'DELETE'], allowHeaders: ['Content-Type', 'Authorization', 'Accept'],})
1 回答

斯蒂芬大帝
TA贡献1827条经验 获得超8个赞
找到问题了,在koa的配置里,我把托管静态文件的中间件放到了跨域配置的中间件前面,导致在请求静态文件时,服务器没有处理静态文件的跨域问题。
现将跨域配置的中间件的顺序提前,解决了问题。
添加回答
举报
0/150
提交
取消