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

试图连接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 

如何closuresSSL连接? 这是我的环境设置

  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' } } }; 

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

当没有明确要求knex试图强制使用ssl连接的时候,没有任何理由(实际上pg驱动程序负责这个部分)。

你可能想用这个作为连接heroku的基础,然后在这上面进行更复杂的configuration:

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