我正在尝试将带有后端的 React 应用程序部署到 github 页面上的同一个存储库中。一切正常,直到我向其中添加后端代码。我可以部署前端,但我不知道如何将后端部署到github。
在我的 package.json 中,我有以下内容:
....
"scripts": {
"start": "react-scripts start",
"server": "nodemon server.js",
"client": "npm run start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\""
}
...
我已经推送到github了。安装了 gh-pages 包。
我已经添加了
"homepage" : "https://[your-user-name].github.io/[your-repo-name]/"
“predeploy”:
“deploy”:
我认为这是我出错的地方。我知道 predeploy 和 deploy 应该指定什么,但我尝试输入一千个不同的版本,但出现错误。
最佳答案
Github 页面不会执行任何服务器端代码。您只能上传静态文件(html、css、js、图片等)。
为了拥有托管后端,您应该寻找其他服务,例如 Google Cloud、AWS Lambda、Heroku 等。
关于reactjs - 在同一个存储库中的 github 页面前端和后端上部署 React 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52969697/