正如标题所说的,当我在那里部署我的系统时,当我输入heroku logs时,我得到了以下两个错误:
(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"
}}
发布于 2020-11-03 18:30:58
因此,作为将来任何人面临同样问题的参考,我已经找到了答案,我在那里有两个问题。
首先,我的IP地址是MongoDB群集上唯一列入白名单的IP,因此我将其编辑为所有IP。因为heroku将使用与我不同的Ip地址,所以我将其设为0.0.0.0/0,以将所有Ip列入白名单。
第二个问题是超时,因为在路由中有两个等待函数,中间有另一个函数,那就是向用户发送电子邮件,所以我在第二个等待之后移动了那个函数,这样服务器就不会回复超时,因为很明显,对于这三个函数,当我读到Heroku文档时,它会导致专门发送电子邮件的超时。
https://stackoverflow.com/questions/64650961
复制相似问题