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

laik7k3q  于 2022-11-13  发布在  其他
关注(0)|答案(2)|浏览(133)

我正在使用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
我的包参:

{
  "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"
  }
}
7z5jn7bk

7z5jn7bk1#

问题是pg版本8.x会破坏heroku。连接常数需要为:

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

pwuypxnk2#

经过这么多的斗争,这对我来说很有效:

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

相关问题