Heroku应用抛出错误:自签名证书

时间:2020-05-30 05:11:07

标签: node.js express heroku

我正在使用heroku的免费层来部署应用程序。我已经成功在heroku上成功创建了应用程序。我推到heroku并尝试了heroku local,该应用程序可以正常运行。但是,如果我尝试heroku open,浏览器将打开至heroku“应用程序错误”页面。

我尝试运行NODE_ENV=production heroku local作为故障排除步骤,但这确实导致应用程序损坏。我得到

Error: self signed certificate
at TLSSocket.onConnectSecure (_tls_wrap.js:1492:34)
at TLSSocket.emit (evens.js:315:20)
at TLSSocket._finishInit (_tls_wrap.js:935:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:693:12)

github仓库在这里:https://github.com/JoeCastr/budget_app

我的package.json:

{
  "name": "budget_app_project",
  "version": "1.0.0",
  "description": "",
  "main": "budget.js",
  "scripts": {
    "start": "npx nodemon budget.js",
    "heroku-postbuild": "npm install --production",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "eslint": "^6.8.0",
    "eslint-config-airbnb-base": "^14.1.0",
    "eslint-plugin-import": "^2.20.2",
    "nodemon": "^2.0.3"
  },
  "dependencies": {
    "bcrypt": "^4.0.1",
    "connect-loki": "^1.1.0",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "express-flash": "0.0.2",
    "express-session": "^1.17.1",
    "express-validator": "^6.5.0",
    "morgan": "^1.10.0",
    "pg": "^8.2.1",
    "pug": "^2.0.4"
  },
  "engines": {
    "node": "13.12.0",
    "npm": "6.14.4"
  }
}

2 个答案:

答案 0 :(得分:0)

问题是pg版本8.x破坏了heroku。连接常数必须为:

const CONNECTION = {connectionString:process.env.DATABASE_URL,ssl:{rejectUnauthorized:false}}

答案 1 :(得分:0)

经过这么多的挣扎,这对我有用:

const pool = new Pool({
  connectionString: process.env.yourDatabaseURL, (from heroku)
    ssl: { rejectUnauthorized: false }
  
})