部署系统后,我一直在heroku上收到Cannot GET/



正如标题所说,在我将系统部署到那里之后,我一直得到Cannot GET/,所以当我键入heroku日志时,我会得到以下两个错误:第一个

(node:23) UnhandledPromiseRejectionWarning: MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.

即使我为开发服务器和生产服务器修复了参数变量,为了使用mongoose进行连接,我在代码中有process.env.MONGODB,它在开发服务器上正常工作。

第二个错误是

(node:23) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)    

并且它没有引用特定的代码、行或文件来知道错误的确切位置是

这些是我对系统的依赖项

{
"name": "task-manager",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node src/app.js",
"dev": "env-cmd -f ./config/dev.env nodemon src/app.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@sendgrid/mail": "^7.3.0",
"bcryptjs": "^2.4.3",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"mongodb": "^3.6.2",
"mongoose": "^5.10.9",
"multer": "^1.4.2",
"sharp": "^0.26.2",
"validator": "^13.1.17"
},
"devDependencies": {
"env-cmd": "^10.1.0",
"nodemon": "^2.0.5"
}

}

所以作为一个参考,以防将来有人面临同样的问题,我已经找到了答案,我有两个问题。

首先,我的IP地址是MongoDB集群上唯一被列入白名单的IP,所以我编辑了它,使其成为所有IP,因为heroku将使用与我不同的IP地址,我将其设为0.0.0.0/0,以将所有IP列入白名单。

第二个问题是超时,因为一条路由中有两个等待函数,中间有另一个函数,那就是向用户发送电子邮件,所以我在第二个等待之后移动了该函数,这样服务器就不会回复超时,因为很明显,这三个函数会导致超时,特别是发送电子邮件,正如我在Heroku文档中所读到的那样。

最新更新