[英]How to host nodeJS server and react app on heroku
我已經上傳了服務器和react客戶端,但是服務器界面是顯示的界面,而不是react界面。
我嘗試將服務器的package.json文件中的“腳本”部分混在一起,但這似乎無濟於事。
服務器的package.json如下所示:
{
"name": "application",
"version": "0.0.0",
"private": true,
"engines": {
"node": "9.11.2",
"npm": "6.x"
},
"dependencies": {
"cookie-parser": "~1.4.4",
"cors": "^2.8.5",
"csv-parser": "^2.3.0",
"debug": "~2.6.9",
"express": "~4.16.1",
"express-mysql-session": "^2.1.0",
"express-session": "^1.16.2",
"http-errors": "~1.6.3",
"jade": "~1.11.0",
"md5": "^2.2.1",
"morgan": "~1.9.1",
"multer": "^1.4.1",
"mysql": "^2.17.1",
"node-stringify": "^0.2.1",
"xmlbuilder": "^13.0.2"
},
"devDependencies": {
"nodemon": "^1.19.1"
},
"scripts": {
"start": "node ./bin/www",
"client": "cd frontend && npm start",
"heroku-postbuild": "cd frontend && npm install && npm run build"
}
}
這是客戶端的package.json(在這種情況下為前端):
{
"name": "app-frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"@navjobs/upload": "^3.1.3",
"async-validator": "^1.8.2",
"axios": "^0.17.0",
"canvas2pdf": "^1.0.5",
"express": "^4.16.3",
"file-exists": "^5.0.1",
"fs2": "^0.3.4",
"howler": "^2.0.5",
"html2canvas": "^1.0.0-alpha.12",
"js-file-download": "^0.4.7",
"jspdf": "^1.3.5",
"moment": "^2.22.1",
"paginate-array": "^2.0.0",
"path-exists": "^4.0.0",
"react": "^16.3.1",
"react-d3-tree": "^1.13.0",
"react-dom": "^16.2.0",
"react-google-login": "^3.0.10",
"react-helmet": "^5.2.0",
"react-html-parser": "^2.0.2",
"react-native": "^0.55.2",
"react-native-fs": "^2.13.3",
"react-pagination-table": "^2.0.2",
"react-redux": "^5.0.6",
"react-reveal": "^1.2.1",
"react-router-dom": "^4.2.2",
"react-router-redux": "^5.0.0-alpha.9",
"react-scripts": "^2.1.0",
"react-style-tag": "^2.0.1",
"react-toastify": "^4.0.0-rc.4",
"reactable": "^1.1.0",
"redux": "^3.7.2",
"redux-logger": "^3.0.6",
"redux-pack": "^0.1.5",
"redux-thunk": "^2.2.0",
"semantic-ui-css": "^2.2.14",
"semantic-ui-react": "^0.79.1",
"shape-json": "^1.2.4",
"styled-components": "^4.3.2",
"underscore": "^1.9.0",
"url-exists": "^1.0.3",
"vis": "^4.21.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"precommit": "lint-staged"
},
"devDependencies": {
"husky": "^0.14.3",
"lint-staged": "^4.2.3",
"prettier": "^1.7.2"
},
"lint-staged": {
"*.js": [
"prettier --tab-width 2 --single-quote --jsx-bracket-same-line --write",
"git add"
]
},
"proxy": "http://localhost:3001"
}
這是我的文件結構:
.
└── application
├── app.js
├── assets
├── bin
├── controllers
├── frontend
│ ├── index.js
│ ├── package.json (this is the package.json for the frontend)
│ ├── public
│ ├── README.md
│ └── src
├── models
├── node_modules
├── package.json (this is the package.json for the server)
├── package-lock.json
├── public
├── routes
└── views
為了以防萬一,我的服務器端口偵聽器位於/bin/www
。 我定義了一個端口,然后創建一個server = createHttpServer()
,其中server變量是偵聽該端口的變量,並將其導入app.js中。
如果有人知道如何解決我的問題,請幫助我。 我想測試在線部署我的應用程序。
當您使用create-react-app時,這可能是自動git init的問題-您的前端文件夾可能有自己的git文件夾。 這會導致我稱之為gitception的問題。 當您進行git init並從根目錄創建heroku時-您將在根目錄中擁有另一個git文件夾。 當您推送到heroku時-它不包括前端文件夾b / c,它是一個單獨的git實例。 您可以通過在編輯器中打開項目並可視化隱藏文件來更正此問題,以便查看git文件夾。 將前端git文件夾移至垃圾箱。 現在,您需要從緩存中刪除前端git實例:git rm -f --cached frontend && git add。 && git commit -m'將前端文件夾添加回git repo'&& git push heroku master
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.