React/Electron生产构建在从index.html加载manifest.json时出现CORS错误。

10 浏览
0 Comments

React/Electron生产构建在从index.html加载manifest.json时出现CORS错误。

我正在尝试使用JSONLoader将本地存储在计算机上的3D模型加载到Three.js中,而且这个3D模型与整个网站位于同一目录中。

我遇到了\"跨域请求仅支持HTTP。\"的错误,但我不知道是什么原因导致的,也不知道如何解决。

admin 更改状态以发布 2023年5月21日
0
0 Comments
  • Start the server with the command http-server

  • This will serve the files in your directory at http://localhost:8080

    You can specify a different port by adding -p PORT to the command, replacing PORT with the desired port number.

  • 通过发出 http-server -c-1 启动您的http服务器。

  • 这将启动一个Node.js httpd,它将您的目录中的文件作为静态文件提供,可从 http://localhost:8080 访问。

    Ruby

    如果您偏好的语言是Ruby ... Ruby风水神说这也可以:

    ruby -run -e httpd . -p 8080
    

    PHP

    当然PHP也有自己的解决方案。

    php -S localhost:8000
    

    0
    0 Comments

    我的水晶球显示你正在使用file://C:/来加载模型,这与错误消息一致,因为它们不是http://

    因此,你可以在本地计算机安装一个Web服务器,或将模型上传到其他地方并使用jsonp,将URL更改为http://example.com/path/to/model

    来源在RFC-6454中被定义为

       ...they have the same
       scheme, host, and port.  (See Section 4 for full details.)
    

    因此,即使你的文件源自同一主机(localhost),但只要方案不同(http / file),它们就被视为不同的起源。

    0