gpt4 book ai didi

node.js - 部署后 Heroku 的应用程序错误

转载 作者:行者123 更新时间:2023-12-03 12:15:27 25 4
gpt4 key购买 nike

成功部署我的应用程序后,我点击了“打开应用程序”,我看到了这个错误:

Application error
An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command
heroku logs --tail

链接错误 https://fcrg.herokuapp.com/

但它确实在本地主机中使用 yarn dev cli 正常工作

后端应用程序的 package.json :
{
"name": "site-web-france",
"version": "1.0.0",
"scripts": {
"start": "node server.js",
"heroku-postbuild": "cd client && npm install && npm install --only=dev --no-shrinkwrap && npm run build",
"client": "cd client && yarn start",
"server": "nodemon server.js",
"dev": "concurrently --kill-others-on-fail \"yarn server\" \"yarn client\"",
"dev:server": "cd client && yarn build && cd .. && yarn start",
"start": "node server.js",
"heroku-postbuild": "cd client && npm install && npm install --only=dev --no-shrinkwrap && npm run build"
},
"dependencies": {
"body-parser": "^1.18.3",
"express": "^4.16.3",
"mongodb": "^3.1.1",
"mongoose": "^5.2.6",
"react-scripts": "^1.1.4"
},
"devDependencies": {
"concurrently": "^3.5.0"
}
}

我认为这个问题是因为“ yarn ”,你怎么看?

教程如下:
https://medium.freecodecamp.org/how-to-make-create-react-app-work-with-a-node-backend-api-7c5c48acb1b0

最佳答案

确保应用程序端口不是硬编码的,例如:
app.listen(3000, ...)
它可能会导致 Heroku 出现问题。而是尝试使用环境变量 PORT :
app.listen(process.env.PORT || 3000, ...)
希望能帮助到你!

关于node.js - 部署后 Heroku 的应用程序错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51842024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com