我的应用程序在Heroku中部署成功,但在打开应用程序时显示错误



我的应用程序成功部署到Heroku..

****:已部署6bc02eb8今天下午4:19·v23·比较差异**** ****:构建今天下午4:18·查看构建日志

但是当尝试打开我的应用程序时显示错误…

2022 - 06 - 29 - t10:19:45.228279 + 00:00应用(网络。[1]: npm ERR!2022 - 06 - 29 - t10:19:45.228377 + 00:00应用(网络。[1]: npm ERR!失败了blog-application@1.0.0启动脚本。2022 - 06 - 29 - t10:19:45.228470 + 0(web应用程序。[1]: npm ERR!这可能不是npm的问题。有可能是上面附加的日志输出。2022 - 06 - 29 - t10:19:45.236802 + 00:00应用[web.1]:2022 - 06 - 29 - t10:19:45.237020 + 00:00应用(网络。[1]: npm ERR!完整的日志此运行的详细信息见于:2022-06-29T10:19:45.237112+00:00(web应用程序。[1]: npm ERR!
/app/.npm/_logs/2022 - 06 - 29 - t10_19_45_229z debug.log2022 - 06 - 29 - t10:19:45.431649 + 00:00 heroku [web。1]:进程退出状态1 2022-06-29T10:19:45.541882+00:00 heroku[web。1]:状态改变2012-06-29 10:19:48.705353+00:00heroku[router]: at=error code=H10 desc= App crash "方法=获取路径="/";主机= syt-share-your-thoughts.herokuapp.comrequest_id = 0 bb2aaff -公元前6 - 41 - fb - 891 e - d3b361a122f8 fwd ="59.153.103.22"绝妙的= =服务=连接状态= 503字节= = https协议2022-06-29T10:19:51.151462+00:00 heroku[router]: at=error code=H10crashed"desc =";应用;方法=得到路径="/favicon.ico"主机= syt-share-your-thoughts.herokuapp.comrequest_id = c0d24108 - 01 - a7 - 44 - b7 - 96 - dd - e8cc62bcaa7c fwd ="59.153.103.22"Dyno = connect= service= status=503 bytes= protocol=https

这是我的包裹。json文件:
{
"name": "blog-application",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "node app.js",
"dev": "nodemon app.js"
},
"author": "Md Shareful Islam",
"license": "ISC",
"dependencies": {
"bcrypt": "^5.0.1",
"chalk": "^4.1.0",
"cheerio": "^1.0.0-rc.11",
"config": "^3.3.7",
"connect-flash": "^0.1.1",
"connect-mongodb-session": "^3.1.1",
"debug": "^4.3.4",
"dotenv": "^16.0.1",
"ejs": "^3.1.8",
"express": "^4.18.1",
"express-session": "^1.17.3",
"express-validator": "^6.14.1",
"moment": "^2.29.3",
"mongoose": "^6.3.8",
"morgan": "^1.10.0",
"multer": "^1.4.5-lts.1",
"nodemon": "^2.0.16",
"reading-time": "^1.5.0",
"validator": "^13.7.0"
},
"engines": {
"node": "14.15.5"
}
}
这是我的主文件:
require('dotenv').config()
const express = require('express');
const mongoose = require('mongoose')
const config = require('config')
const chalk = require('chalk')
// import middleware
const setMiddleware = require('./middleware/middleware')
//Import Routes
const setRoutes = require('./routes/routes')

const MONGODB_URI = `mongodb+srv://${config.get('db-admin')}:${config.get('db-password')}@blogapp.ool50gr.mongodb.net/?retryWrites=true&w=majority`
const app = express();
// Setup View Engine
app.set('view engine', 'ejs')
app.set('views', 'views')
// Using Middleware from Middleware Directory
setMiddleware(app)
// Using Routes from Route Directory
setRoutes(app)
// ** middleware to handle 404 and 500.
app.use((req, res, next) => {
let error = new Error('404 Page Not Found');
error.status = 404;
next(error);
})
app.use((error, req, res, next) => {
if(error.status === 404) {
return res.render('pages/error/404', {flashMessage: {}})
}
res.render('pages/error/500', {flashMessage: {}})
})
const PORT = process.env.PORT || 8080;
mongoose.connect(MONGODB_URI, 
{useNewUrlParser: true})
.then(() => {
console.log(chalk.green.bold('Database connected!'))
app.listen(PORT, () => {
console.log(chalk.green.italic(`App is running on PORT ${PORT}`));
});
})
.catch(e => {
return console.log(e)
})

Here is log detail from Heroku…

2022-06-29T16:18:56.404997+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2022-06-29T16:18:56.405076+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2022-06-29T16_18_56_398Z-debug.log
2022-06-29T16:18:56.554135+00:00 heroku[web.1]: Process exited with status 1
2022-06-29T16:18:56.637092+00:00 heroku[web.1]: State changed from starting to crashed
2022-06-29T16:18:56.640222+00:00 heroku[web.1]: State changed from crashed to starting
2022-06-29T16:19:00.220649+00:00 heroku[web.1]: Starting process with command `npm start`
2022-06-29T16:19:03.473783+00:00 app[web.1]: 
2022-06-29T16:19:03.473792+00:00 app[web.1]: > blog-application@1.0.0 start /app
2022-06-29T16:19:03.473792+00:00 app[web.1]: > node app.js
2022-06-29T16:19:03.473792+00:00 app[web.1]: 
2022-06-29T16:19:35.090006+00:00 app[web.1]: /app/node_modules/mongodb/lib/utils.js:417
2022-06-29T16:19:35.090017+00:00 app[web.1]:                     throw error;
2022-06-29T16:19:35.090018+00:00 app[web.1]:                     ^
2022-06-29T16:19:35.090019+00:00 app[web.1]: 
2022-06-29T16:19:35.090020+00:00 app[web.1]: Error: Error connecting to db: connection <monitor> to 13.250.175.230:27017 closed
2022-06-29T16:19:35.090021+00:00 app[web.1]:     at /app/node_modules/connect-mongodb-session/index.js:88:17
2022-06-29T16:19:35.090021+00:00 app[web.1]:     at /app/node_modules/mongodb/lib/utils.js:413:17
2022-06-29T16:19:35.090022+00:00 app[web.1]:     at /app/node_modules/mongodb/lib/mongo_client.js:129:28
2022-06-29T16:19:35.090022+00:00 app[web.1]:     at connectCallback (/app/node_modules/mongodb/lib/operations/connect.js:29:9)
2022-06-29T16:19:35.090023+00:00 app[web.1]:     at /app/node_modules/mongodb/lib/operations/connect.js:78:20
2022-06-29T16:19:35.090023+00:00 app[web.1]:     at Object.callback (/app/node_modules/mongodb/lib/sdam/topology.js:208:50)
2022-06-29T16:19:35.090024+00:00 app[web.1]:     at Timeout._onTimeout (/app/node_modules/mongodb/lib/sdam/topology.js:319:33)
2022-06-29T16:19:35.090024+00:00 app[web.1]:     at listOnTimeout (internal/timers.js:554:17)
2022-06-29T16:19:35.090024+00:00 app[web.1]:     at processTimers (internal/timers.js:497:7)
2022-06-29T16:19:35.109275+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2022-06-29T16:19:35.109568+00:00 app[web.1]: npm ERR! errno 1
2022-06-29T16:19:35.113501+00:00 app[web.1]: npm ERR! blog-application@1.0.0 start: `node app.js`
2022-06-29T16:19:35.113599+00:00 app[web.1]: npm ERR! Exit status 1
2022-06-29T16:19:35.113705+00:00 app[web.1]: npm ERR! 
2022-06-29T16:19:35.113792+00:00 app[web.1]: npm ERR! Failed at the blog-application@1.0.0 start script.
2022-06-29T16:19:35.113876+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2022-06-29T16:19:35.120692+00:00 app[web.1]: 
2022-06-29T16:19:35.120808+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2022-06-29T16:19:35.120859+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2022-06-29T16_19_35_114Z-debug.log
2022-06-29T16:19:35.785417+00:00 heroku[web.1]: State changed from starting to crashed
2022-06-29T16:19:35.273101+00:00 heroku[web.1]: Process exited with status 1
2022-06-29T16:19:38.894464+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=syt-share-your-thoughts.herokuapp.com request_id=2b13bcd5-e764-4e60-a254-394a8b0f7531 fwd="59.153.103.22" dyno= connect= service= status=503 bytes= protocol=https
2022-06-29T16:19:41.185482+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=syt-share-your-thoughts.herokuapp.com request_id=6109b89a-818d-4827-804b-98c1a875a3ab fwd="59.153.103.22" dyno= connect= service= status=503 bytes= protocol=https

如果您没有提供足够的信息让我们能够帮助您,那么在这方面,没有人可以也不会为您调试它。

在这里,分享您的package.json

和您的应用程序的入口文件将是有用的!无论如何,npm run start似乎正在崩溃,你可以首先确保npm run start运行的任何命令都可以在heroku中访问(你可能使用你在本地机器上安装的全局依赖项,而heroku没有)。

如果您提供所需的代码片段以便我们了解正在发生的事情,我将很高兴帮助您更多!

相关内容