Knex:错误池2 - 错误:服务器不支持SSL连接

时间:2017-05-28 11:08:16

标签: node.js postgresql knex.js

尝试连接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部分。没有运气。

1 个答案:

答案 0 :(得分:0)

没有理由说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);
  });