【问题标题】:i keep getting Cannot GET / on heroku after deploying my system部署我的系统后,我一直无法获取 / 在 heroku 上
【发布时间】:2021-02-15 10:18:29
【问题描述】:

正如标题所说,在我在那里部署我的系统之后,我不断收到无法获取 / ,所以当我输入 heroku 日志时,我得到了以下 2 个错误: 首先

(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.

即使我为开发和生产服务器修复了我的参数变量,使用猫鼬连接我在代码中有 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"
 }

}

【问题讨论】:

    标签: node.js heroku npm deployment


    【解决方案1】:

    所以作为参考,以防将来有人遇到同样的问题,我已经找到了答案,我在那里遇到了 2 个问题。

    首先是我的 IP 地址是 MongoDB 集群上唯一列入白名单的 IP,因此我对其进行了编辑以制作所有 IP,因为 heroku 将使用与我不同的 IP 地址,我将其设置为 0.0.0.0/0 以将所有 IP 列入白名单ip的。

    第二个问题是超时,因为路由中有 2 个 await 函数,中间还有另一个函数,即向用户发送电子邮件,所以我在第二个 await 之后移动了该函数,因此服务器不会回复超时,因为显然使用这 3 个函数会导致超时,特别是我在 Heroku 文档中阅读的发送电子邮件。

    【讨论】:

      猜你喜欢
      • 2021-05-03
      • 1970-01-01
      • 2015-02-23
      • 1970-01-01
      • 2021-03-01
      • 2023-03-31
      • 1970-01-01
      • 2011-06-23
      • 1970-01-01
      相关资源
      最近更新 更多