【问题标题】:how to set knex connection ssl options when using a connection string使用连接字符串时如何设置 knex 连接 ssl 选项
【发布时间】:2015-08-19 14:15:34
【问题描述】:

当我使用连接字符串初始化 knex 时,如何将连接的 ssl 属性设置为 true?同样如何将调试设置为true?我通常会传入一个连接对象,但在这种情况下,我必须使用环境变量中的连接字符串。

var database = {
    client: 'pg',
    connection: connstr //normally I would pass in the object below
    //connection: {
    //    "host": config.get('database_host'),
    //    "user": config.get('database_user'),
    //    "password": config.get('database_password'),
    //    "database": config.get('database_name'),
    //    "debug": config.get('database_debug'),
    //    "ssl":config.get('database_ssl')
    //}
};

var knex = require('knex')(database);
knex.connection.ssl = true;  // this doesn't seem to do anything

【问题讨论】:

  • 连接:{ connectionString: process.env.DATABASE_URL, ssl:true, }
  • 我的 SSL Key 有密码,我应该在哪里输入密码?

标签: knex.js


【解决方案1】:

只需将?ssl=true 添加到连接字符串的末尾(在数据库名称的末尾)。对于调试,请在设置 ssl 或 &debug=true 后附加 ?debug=true 我实际上不确定抱歉,所以请尝试两者。

【讨论】:

  • ?ssl=true 是我的解决方案。
  • knexfile connection 块中的 ssl : true 也有效。
  • 我的 SSL Key 有密码,我应该在哪里输入密码?
【解决方案2】:

对于 pg >= 8.x,您需要以下内容:

connection: {
  connectionString: dbConnection,
  ssl: { rejectUnauthorized: false }
}

这个答案把我带到了这里:https://stackoverflow.com/a/66898176/776167

您可以阅读更多here

【讨论】:

  • 这是一个很好的答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-15
  • 2019-01-07
  • 2017-03-17
相关资源
最近更新 更多