我正试图连接到我在Heroku建立的PostgreSQL数据库.

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

// DB Configuration
const sequelize = new Sequelize({
  database: "[wont'd 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(见this GitHub issue)中的(意外) destruct 性更 retrofit 成的.

解决方案是将rejectUnauthorized: false传递给dialectOptions>;ssl,as described here by GitHub user jsanta:

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
    }
  },
});

Postgresql相关问答推荐

尽管Jooq已经是uuid类型,Jooq仍会启用我的UID,为什么?

Postgs密码重置问题

横向联接返回的行数太多

Postgres:如何优化在多个表上搜索列的相似性查询?(Pg_Trgm)

在Ubuntu 18.04 Bionic上安装PostgreSQL(已删除回购)

如何获得一起满足数量要求的物品? (WHILE 循环还是 CTE?)postgresql

Docker compose read connection reset by peer error on pipeline

PostgreSQL TIMESTAMPTZ 不适用于 SpringBoot Java Query

在 jOOQ 中 Select 相同的命名列

将 postgres 从属提升为主 node

在postgresql中按经纬度查找最近的位置

全文搜索(Postgres)与Elastic search

PostgreSQL - jsonb_each

如何在 PostgreSQL 触发器函数中获取表名?

避免 created_at 和 updated_at 由 sequelize 自动生成

无法使用 sequelize 从本地 node 应用程序连接到 heroku postgresql 数据库

如何为 postgres 连接设置 application_name?

按任意时间间隔计算行数的最佳方法

可以为空的列在 PostgreSQL 中是否会占用额外的空间?

重命名 Amazon RDS 主用户名