【问题标题】:Knex:Error Pool2 - Error: The server does not support SSL connectionsKnex:Error Pool2 - 错误:服务器不支持 SSL 连接
【发布时间】:2017-10-28 19:46:52
【问题描述】:

尝试连接Postgres Node js,遇到错误

Resource Wall is listening on port 8080
Knex:Error Pool2 - Error: The server does not support SSL connections
Knex:Error Pool2 - Error: The server does not support SSL connections

如何关闭 SSL 连接?这是我的环境设置

    DB_HOST=localhost
    DB_USER=postgres
    DB_PASS=password
    DB_NAME=dbname
    DB_SSL=true if heroku
    DB_PORT=5432

还有我的 knexfile.js

require('dotenv').config();

module.exports = {

  development: {
    client: 'postgresql',
    connection: {
      host     : process.env.DB_HOST,
      user     : process.env.DB_USER,
      password : process.env.DB_PASS,
      database : process.env.DB_NAME,
      port     : process.env.DB_PORT,
      ssl      : process.env.DB_SSL
    },
    migrations: {
      directory: './db/migrations',
      tableName: 'migrations'
    },
    seeds: {
      directory: './db/seeds'
    }
  },

  production: {
    client: 'postgresql',
    connection: process.env.DATABASE_URL + '?ssl=true',
    pool: {
      min: 2,
      max: 10
    },
    migrations: {
      tableName: 'migrations'
    }
  }

};

由于我在 dev 中运行,我预计它不会通过 SSL。也尝试从对象和 URL 中删除该 SSL 部分。没有运气。

【问题讨论】:

  • 如果您没有添加任何技巧来使 ssl 工作,knex 将不会尝试使用 ssl 连接来连接 postgres。您确定这是删除配置的 SSL 部分后遇到的错误吗?您确定您使用的是该 knexfile 进行连接吗?

标签: node.js postgresql knex.js


【解决方案1】:

当没有明确要求 knex 尝试强制使用 ssl 连接时,没有理由这样做(实际上 pg 驱动程序会处理该部分)。

您可能希望以此为基础连接 heroku,然后在此基础上进行更复杂的配置:

const knex = require('knex')({
  client: 'pg',
  connection: 'postgres://user:pass@server:port/database'
});

knex.raw('select 1')
  .then(res => {
    console.log('Success');
  })
  .catch(err => {
    console.log('Something failed', err);
  });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-15
    • 2021-12-17
    • 2020-07-23
    • 2022-07-23
    • 1970-01-01
    • 2020-05-27
    • 1970-01-01
    • 2022-01-03
    相关资源
    最近更新 更多