代码之家  ›  专栏  ›  技术社区  ›  mojo45

React三光纤似乎突然需要一个资源,导致我的应用程序崩溃。安全问题还是其他什么?

  •  0
  • mojo45  · 技术社区  · 2 年前

    正如标题所提到的,这个应用程序运行得非常好。有一天,我去查看它,在控制台中看到了这个错误:

    相关错误1: 访问“”获取https://market-assets.fra1.cdn.digitaloceanspaces.com/market-assets/hdris/st-fagans/st_fagans_interior_1k.hdr'来自原点'http://localhost:5173'已被CORS策略阻止:请求的资源上不存在“Access Control Allow Origin”标头。如果不透明响应满足您的需求,请将请求的模式设置为“无cors”,以在禁用cors的情况下获取资源。 market assets.fra1.cdn.digitaloceanspaces.com/market assets/hdris/st-fagans/st_fagans_interior_1k.hdr:1

    相关错误2: 未能加载资源:net::ERR_Failed 2index.js:21未捕获错误:无法加载st fagans/st_fagans_interior_1k.hdr:无法获取) 在Object.oError(index-22ee0173.esm.js:1648:36) 在three.module.js:41524:39

    See here the network initator snippet showing that it's coming from react-three-fiber

    我自己从来没有明确请求过这个资源,所以我不确定如何亲自更新cors策略。我的应用程序确实有一个启用了CORS的服务器端。

    请让我知道你认为这可能是什么,如果有什么解决方案让你眼前一亮。谢谢

    除非我真的只是空白,否则我不记得在应用程序工作和出现这个错误之间对它做过任何更改,所以我有点困惑。在这个项目中使用vite。

    1 回复  |  直到 2 年前
        1
  •  1
  •   AKX Bryan Oakley    2 年前

    该文件名被引用 here 在里面 drei 的源作为名为的(HDR)环境的文件 lobby

    源服务器中一定有更改 market-assets.fra1.cdn.digitaloceanspaces.com 的配置不为该文件提供CORS头;这显然 is a known issue with the drei folks

    正在更新 drei 在你的应用程序中可能会解决这个问题(因为它会更改内容以指向另一个CDN)。

    当然,如果你在本地与应用程序一起托管HDR文件会更好,这样你就不会受第三方CDN的摆布。

        2
  •  1
  •   Darmendas    2 年前

    也有同样的问题,但只是在我的实时应用程序上,而不是在本地应用程序上。更新到最新/drei将问题转移到我的本地。

    最后更新到9.40.7为我修复了本地nd live上的问题