gpt4 book ai didi

javascript - Sequelize连接错误: self signed certificate

转载 作者:行者123 更新时间:2023-12-02 21:01:16 24 4
gpt4 key购买 nike

我正在尝试连接到我在 Heroku 中设置的 PostgreSQL 数据库。

const { Sequelize, DataTypes, Model } = require("sequelize");

// DB Configuration
const sequelize = new Sequelize({
database: "[won't show db]",
username: "[won't show username]",
password: "[won't show password]",
host: "ec2-54-221-195-148.compute-1.amazonaws.com",
port: 5432,
dialect: "postgres",
dialectOptions: {
ssl: true,
},
});

这就是我得到的输出:

SequelizeConnectionError: self signed certificate

最佳答案

这是由于 node-postgres 版本 8 中的(意外)重大更改造成的(请参阅 this GitHub issue)。

解决方案是将 rejectUnauthorized: false 传递给 dialectOptions>ssl 内的 sequelize 连接参数,如described here by GitHub user jsanta ,绕过 SSL 证书检查(当通过安全连接(例如在本地主机上或同一网络中您自己的服务器之间)连接到受信任的服务器时,这是可以的):

const sequelize = new Sequelize({
database: "xxxxx",
username: "xxxxx",
password: "xxxxx",
host: "xxxxx",
port: 5432,
dialect: "postgres",
dialectOptions: {
ssl: {
require: true,
rejectUnauthorized: false // <<<<<<< YOU NEED THIS
}
},
});

关于javascript - Sequelize连接错误: self signed certificate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61350186/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com