【问题标题】:Unable to connect nodejs app to Postrgres database on heroku using typeorm无法使用 typeorm 将 nodejs 应用程序连接到 heroku 上的 Postgres 数据库
【发布时间】:2021-12-25 08:54:24
【问题描述】:

我正在使用 typeorm 连接到我的 nodejs 应用程序上的 Postgres 数据库。我能够在本地成功连接,但在部署到 heroku 后,根据我的数据库配置出现这些错误。

import { createConnection } from 'typeorm';
...

export const databaseConnection = async (databaseURL:string) => {
    try {
        await createConnection({
            type: "postgres",
            url: databaseURL,
            entities: [User],
            synchronize: true,
            ssl:  false
        });
        

    } catch (error) {
    }
};

databaseConnection("<DATABASE_URL_FROM_HEROKU>")

当我这样做时,我收到错误 no pg_hba.conf entry for host , userdatabase SSL off at Parser.parseErrorMessage

当我在连接中使用ssl: true 时,我收到错误:Error: self signed certificate at TLSSocket.onConnectSecure heroku

当我完全删除 ssl 属性时,它仍然没有工作。

我遇到的大多数解决方案都是使用像 here 这样的 sequelize 完成的。但我正在使用 typeorm。请我摆脱这个错误。

【问题讨论】:

    标签: node.js postgresql heroku typeorm


    【解决方案1】:

    你试过这样吗:

    await createConnection({
      type: "postgres",
      url: databaseURL,
      entities: [User],
      synchronize: true,
      ssl: {
        rejectUnauthorized: false
      }
    });
    

    【讨论】:

    • 它抛出错误:Error: The server does not support SSL connections at Socket.
    猜你喜欢
    • 1970-01-01
    • 2020-07-13
    • 1970-01-01
    • 2013-11-30
    • 2013-04-21
    • 2021-07-10
    • 2023-03-14
    • 2021-09-04
    • 2013-09-17
    相关资源
    最近更新 更多