node.js - 无法使用 typeorm 将 nodejs 应用程序连接到 heroku 上的 Postrgres 数据库
问题描述
我正在使用 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 属性时,它仍然不起作用。
我遇到的大多数解决方案都是在这里使用 sequelize 完成的。但我正在使用 typeorm。我请我摆脱这个错误。
解决方案
你有没有尝试过这样的:
await createConnection({
type: "postgres",
url: databaseURL,
entities: [User],
synchronize: true,
ssl: {
rejectUnauthorized: false
}
});
推荐阅读
- python - 在 pytorch 或 huggingface/transformer 标签的代码中哪里被“重命名”为标签?
- android - com.example.androiddata.databinding.FragmentDetailBindingImpl.executeBindings(FragmentDetailBindingImpl.java:147)
- jquery - JSP 上的 JQUERY AJAX 和 SELECT ELEMENT
- c++ - 如何在 Visual Studio 2015 中使用 C++ 语言?
- android - 如何恢复意外删除的 Flutter 代码文件?
- nlp - 在 spacy 中使用 glove.6B.100d.txt 嵌入得到零 lex.rank
- r - 在 Ubuntu v20.04 上的 R v4.0.1 上安装 mclust 包 v5.4.6 挂起
- python-3.x - 获取 BackgroundScheduler 作业的活动实例数
- javascript - 必须添加额外的依赖来响应 useCallback 依赖列表
- r - R中的ggplot:x轴值从99之后的原点开始