SequelizeConnectionError:自签名证书 [英] SequelizeConnectionError: self signed certificate

查看:337
本文介绍了SequelizeConnectionError:自签名证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to connect to a PostgreSQL Database that I've set up in Heroku.

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:自签名证书

SequelizeConnectionError: self signed certificate


推荐答案

这是由于 node-postgres 版本8中的(意外)重大更改(请参阅此GitHub问题)。

This is due to an (accidental) breaking change in node-postgres version 8 (see this GitHub issue).

解决方案是通过 rejectUnauthorized:对 sequelize 连接参数的错误,如在此由GitHub用户jsanta 描述:

The solution is to pass rejectUnauthorized: false to the sequelize connection parameters, as described here by GitHub user jsanta:

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: {
      require: true,
      rejectUnauthorized: false // <<<<<<< YOU NEED THIS
    }
  },
});

这篇关于SequelizeConnectionError:自签名证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆