首页 > 解决方案 > 如何在 Spring Boot 后端配置 React 应用程序以在 localhost 8080 中启动

问题描述

这是我的 package.json 反应。

{
  "name": "reactjs",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "bootstrap": "^4.5.3",
    "react": "^17.0.1",
    "react-bootstrap": "^1.4.0",
    "react-dom": "^17.0.1",
    "react-scripts": "4.0.0",
    "web-vitals": "^0.2.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"

  },
  "proxy": "http://localhost:8080",
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

我在 package.json 文件中使用了代理,但它对我不起作用。添加此代理后,它没有显示任何错误,但也托管在本地 host3000 中。

标签: reactjsspring-bootintegration

解决方案


React 通常是前端框架。这意味着在一天结束时,它将被构建成一堆 js 文件。因此react-scripts build。您应该将这些文件部署到可以提供静态文件的适当 HTTP 服务器。检查这个以使 HTTP 文件服务器脱离节点https://stackoverflow.com/a/16350826/3849555react-scripts start只是为了开发目的而启动 Web 服务器。不要将其用作真正的 Web 服务器。


推荐阅读