【问题标题】:Unable to connect Objection/Knex to Heroku Postgres无法将 Objection/Knex 连接到 Heroku Postgres
【发布时间】:2021-04-17 20:15:08
【问题描述】:

我正在运行一个带有 objection.js 的 express 节点应用程序,它在 Heroku 上使用 knex。每当我向建立数据库连接的端点发出请求时,都会收到以下错误。

错误 invalid_authorization_specification(代码 28000)甚至意味着什么?

如有任何建议,我们将不胜感激

{
    "name": "DBError",
    "nativeError": {
        "length": 164,
        "name": "error",
        "severity": "FATAL",
        "code": "28000",
        "file": "auth.c",
        "line": "496",
        "routine": "ClientAuthentication"
    },
    "client": "postgres"
}

我的 knexfile 包含以下内容。我也试过用connection: process.env.DATABASE_URL,还是没有骰子。

const db_url = process.env.DATABASE_URL
var db_url_groups = db_url.match(/^.*\/\/(.*):(.*)@(.*):.*\/(.*)$/)
var dbUser = db_url_groups[1]
var dbPw = db_url_groups[2]
var dbHost = db_url_groups[3]
var db = db_url_groups[4]
  
module.exports = {
 development: {
     client: 'pg',
     useNullAsDefault: true,
     connection: {
       host : 'db',
       user : 'test',
       password : 'test',
       database : 'local_db'
     }
 },
 production: {
   client: 'pg',
   useNullAsDefault: true,
   connection: {
     host : `${dbHost}`,
     user : `${dbUser}`,
     password : `${dbPw}`,
     database : `${db}`
   }
 }
}

【问题讨论】:

    标签: knex.js heroku-postgres objection.js


    【解决方案1】:

    该问题与 SSL 有关。在连接属性中,我需要添加一个带有以下内容的 ssl 属性:

    ssl:{ 要求:假, 拒绝未授权:假 }

    【讨论】:

      猜你喜欢
      • 2019-07-15
      • 1970-01-01
      • 1970-01-01
      • 2014-11-24
      • 2017-05-28
      • 2020-07-14
      • 2019-05-04
      • 2020-03-03
      • 2018-01-24
      相关资源
      最近更新 更多