reactjs - 如何在 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 中。
解决方案
React 通常是前端框架。这意味着在一天结束时,它将被构建成一堆 js 文件。因此react-scripts build
。您应该将这些文件部署到可以提供静态文件的适当 HTTP 服务器。检查这个以使 HTTP 文件服务器脱离节点https://stackoverflow.com/a/16350826/3849555。react-scripts start
只是为了开发目的而启动 Web 服务器。不要将其用作真正的 Web 服务器。
推荐阅读
- python - 使用 while 循环的 Runge Kutta 算法
- python-3.x - 用 Beautiful Soup 抓取网页的哈希结果
- android - 数据传递失败 putExtra
- php - 如何通过终端在本地主机上执行 php 文件的 cronjob
- java - 使用 FileInputStream 从相对路径读取文件
- amazon-web-services - 将 ElasticSearch 置于 AWS 上的代理之后?
- java - 如何从 JTextField 获取价值到 JComboBox?
- c - 动态二维数组的 C 结构:对象 0x7ffeee94ab80 的错误:未分配被释放的指针
- excel - 跨列的目标搜索宏扫描
- wordpress - WordPress 主题开发用户定义的图像选择