简体   繁体   English

Heroku 无法使用 Node.js 连接到 postgres 数据库

[英]Heroku cannot connect to postgres database using Node.js

I am writing a full stack program in NodeJS, using Heroku and Postgresql.我正在使用 Heroku 和 Postgresql 在 NodeJS 中编写一个完整的堆栈程序。 When I try to make a request through Heroku it times out.当我尝试通过 Heroku 发出请求时,它会超时。 Here are the Heroku logs:以下是 Heroku 日志:

2021-04-14T23:39:01.483427+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/folders" host=damp-everglades-28835.herokuapp.com request_id=7bcfc1a9-bb04-4618-bc1b-211dcedf57c3 fwd="68.81.3.154" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=https
2021-04-14T23:39:01.489279+00:00 app[web.1]: GET /folders - - - - ms

At first, I tried to use pg version 8.xx and it would not build.起初,我尝试使用 pg 版本 8.xx,但它无法构建。 I would get this error: Self signed certificate error, using pg 8.XX.我会收到此错误:自签名证书错误,使用 pg 8.XX。 Version 8 won't even deploy版本 8 甚至不会部署

    Package pg version 8.x.x not tested
    Please raise issue to support pg > 7.x.x
    [7:31:53 PM] table schemaversion does not exist - creating it.
    [7:31:53 PM] version of database is: 0
    [7:31:53 PM] migrating up to 2
    Error: self signed certificate
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1 

Searching for this error suggested adding ssl: false and here is my Postgrator.config where I tried that:搜索此错误建议添加 ssl: false ,这是我尝试过的 Postgrator.config:

```require('dotenv').config();
module.exports = {
    "migrationsDirectory": "migrations",
    "driver": "pg", 
    "connectionString": process.env.DATABASE_URL,
    ssl: {
        rejectUnauthorized: false
      }
}```

SO, To try to fix it I downgraded to 7.4.3 and am stuck with this timeout error.所以,为了尝试修复它,我降级到 7.4.3 并遇到此超时错误。

I can connect to, and modify the database directly.我可以直接连接并修改数据库。 The backend's endpoints that do not use the database work correctly.不使用数据库的后端端点正常工作。 I have triple-checked the credentials on Heroku.我已经对 Heroku 上的凭据进行了三重检查。

Using: Node.js Heroku, javaScript, postgres使用:Node.js Heroku,javaScript,postgres

You can switch back to pg 8. .您可以切换回第 8 页

Your connection config should include ssl.required = true like您的连接配置应包括 ssl.required = true 像

.......
        ssl: {
            required: true,
            rejectUnauthorized: false
          }
........

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM