2017-05-28 74 views
2

服务器在尝试与Postgres的节点连接的js,冲进错误Knex:错误池2 - 错误:不支持SSL连接

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

}; 

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

+0

如果你不加入任何弄虚作假,使SSL工作,knex不会尝试用ssl连接连接postgres。你确定这是删除配置的SSL部分后得到的错误吗?你确定你正在使用该knexfile连接? –

回答

0

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

您可能希望以此为基地,连接Heroku的,然后努力在此之上更复杂的配置:

const knex = require('knex')({ 
    client: 'pg', 
    connection: 'postgres://user:[email protected]:port/database' 
}); 

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