我正在尝试连接到我在 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:自签名证书
这是由于(意外的)重大变化node-postgres
版本 8(参见这个 GitHub 问题 https://github.com/brianc/node-postgres/issues/2009).
解决办法就是通过rejectUnauthorized: false
to the sequelize
里面的连接参数dialectOptions
>ssl
, as GitHub 用户 jsanta 在此描述 https://github.com/brianc/node-postgres/issues/2009#issuecomment-556020509,绕过 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
}
},
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)