【问题标题】:Solution for running REACT web app on (visual studio)code-server behind the proxy situation在代理情况下在 (visual studio)code-server 上运行 REACT web app 的解决方案
【发布时间】:2022-12-17 21:34:17
【问题描述】:

当我们使用 VS 代码服务器开发 Web 应用程序时,预览结果 URL 的默认方法是

http://{yoursite}/proxy/3000

但是,它不适用于 React 开发。

当我们按照官方教程启动一个react应用时,html模板中的所有静态资源总是被重定向到index.html

例如返回 index.html 而不是 /static/js/bundle.js

【问题讨论】:

    标签: reactjs code-server


    【解决方案1】:

    解决该问题,在项目根目录下,打开:

    包.json

    在脚本块中,更改开始属性

    从:

    “开始”:“反应脚本开始”

    至

    “开始” : ”PUBLIC_URL='/absproxy/3000'反应脚本开始” :

      "scripts": {
        
        "start": "PUBLIC_URL='/absproxy/3000/' react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test",
        "eject": "react-scripts eject"
      }

    这也写在下面的文档中。 https://coder.com/docs/code-server/latest/guide#stripping-proxyport-from-the-request-path

    【讨论】:

      【解决方案2】:

      对于那些在端口 3000 上运行另一个应用程序的人,只需简单地执行以下小步骤:

      选修的:

      export PORT=3001

      然后在 package.json 中添加

      "scripts": {    
      "start": "PUBLIC_URL='/absproxy/3001/' react-scripts start",
      "build": "react-scripts build",
      "test": "react-scripts test",
      "eject": "react-scripts eject"
      }
      

      【讨论】:

        猜你喜欢
        • 2013-03-23
        • 1970-01-01
        • 2013-02-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多