[英]at=error code=H10 desc=“App crashed” method=GET path=“/” Error Deploying React/Node to Heroku
我正在嘗試部署一個我正在從事的React on Node項目,並且遇到了一些問題,但我不確定為什么。 以下是從日志中提取的一些信息:
2018-02-11T00:12:22.875338+00:00 app[web.1]: > dmdb@1.0.0 start /app
2018-02-11T00:12:22.875340+00:00 app[web.1]: > node server.js
2018-02-11T00:12:22.875341+00:00 app[web.1]:
2018-02-11T00:12:23.315310+00:00 heroku[web.1]: State changed from starting to crashed
2018-02-11T00:12:23.299113+00:00 heroku[web.1]: Process exited with status 1
2018-02-11T00:13:23.976931+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=dmdb1.herokuapp.com request_id=8d37e10b-6999-4a2f-82bb-f3e724bf1c4e fwd="108.14.98.161" dyno= connect= service= status=503 bytes= protocol=https
根據日志顯示,package.json文件中的啟動腳本似乎存在問題,但是我不確定為什么會用到類似的代碼,因為我已經對成功部署的另一個項目使用了類似的腳本。 我對此進行了一些研究,我相信我的Server.js文件已配置並且端口設置正確,我刪除了依賴關系並確認它在本地有效但未部署,並且自此以來,我已經在vars中設置了SECRET_KEY已設置身份驗證。 以下是我如何設置端口以及后端上的package.json文件的外觀。 如果有人可以提供一些見識,我將不勝感激。 如果我可以提供其他任何信息,請告訴我,我會盡快處理。
來自Server.js的端口:
//app listening on port 1337
const PORT = process.env.PORT || 1337;
app.listen(PORT, () => {
console.log(`LISTENING ON PORT ${PORT}`)
})
從背面更新了Package.json:
{
"name": "dmdb",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js",
"dev": "nodemon server.js",
"debugger": "DEBUG=*:* nodemon server.js",
"prod": "NODE_ENV=production node server.js",
"deploy": "cd client && yarn build && cp -a ./build/ ../public/",
"heroku-postbuid" : "cross-env NODE_ENV=production WEBPACK_CONFIG=browser_prod,server_prod webpack --colors",
},
"engines": {
"node": "8.5.0",
"yarn": "1.3.2"
},
"author": "Dan Levenson",
"license": "MIT",
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.2",
"cookie-parser": "^1.4.3",
"cors": "^2.8.4",
"dotenv": "^4.0.0",
"ejs": "^2.5.7",
"ejs-lint": "^0.3.0",
"express": "^4.16.2",
"express-session": "^1.15.6",
"isomorphic-fetch": "^2.2.1",
"method-override": "^2.3.10",
"morgan": "^1.9.0",
"passport": "^0.4.0",
"passport-local": "^1.0.0",
"path": "^0.12.7",
"pg-promise": "^7.0.3"
}
}
提前致謝!
編輯帖子以包括來自客戶端的Package.JSON:
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-router-dom": "^4.2.2",
"react-scripts": "1.1.0",
"reactstrap": "^5.0.0-beta"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"proxy": "http://localhost:3001"
}
添加構建日志:
-----> Node.js app detected
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NPM_CONFIG_PRODUCTION=true
NODE_VERBOSE=false
NODE_ENV=production
NODE_MODULES_CACHE=true
-----> Installing binaries
engines.node (package.json): 8.5.0
engines.npm (package.json): unspecified (use default)
engines.yarn (package.json): 1.3.2
Resolving node version 8.5.0...
Downloading and installing node 8.5.0...
Using default npm version: 5.3.0
Resolving yarn version 1.3.2...
Downloading and installing yarn (1.3.2)...
Installed yarn 1.3.2
-----> Restoring cache
Loading 2 from cacheDirectories (default):
- node_modules
- bower_components (not cached - skipping)
-----> Building dependencies
Installing node modules (yarn.lock)
yarn install v1.3.2
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.30s.
-----> Caching build
Clearing previous node cache
Saving 2 cacheDirectories (default):
- node_modules
- bower_components (nothing to cache)
-----> Build succeeded!
-----> Discovering process types
Procfile declares types -> web
-----> Compressing...
Done: 20.7M
-----> Launching...
Released v12
https://dmdb-1.herokuapp.com/ deployed to Heroku
使用NPM而不是Yarn重建了應用程序,並且部署沒有問題,並且現在運行良好。 謝謝您的幫助!
此解決方案是可行的 。
通過heroku部署應用程序時,它不允許您指定端口號 。
換句話說,您不能將Web服務的端口號指定為8000或其他名稱,heroku在運行時確定端口號。
因此,您不能使用以下代碼:
log.Fatal(http.ListenAndServe(":8000", router))
您可以做的是獲取heroku的運行時端口。
簡而言之, 只需使用以下代碼 :
log.Fatal(http.ListenAndServe(":" + os.Getenv("PORT"), router))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.