小编Pet*_*tey的帖子

如何将 SSL 证书 (ca-cert) 添加到 node.js 环境变量以连接到 Digital Ocean Postgres 托管数据库?

我目前正在使用 node-postgres 来创建我的池。这是我当前的代码:

const { Pool } = require('pg')

const pgPool = new Pool({
  user: process.env.PGUSER,
  password: process.env.PGPASSWORD,
  host: process.env.PGHOST,
  database: process.env.PGDATABASE,
  port: process.env.PGPORT,
  ssl: {
    rejectUnauthorized: true,
    // Would like to add line below
    // ca: process.env.CACERT,
},
})
Run Code Online (Sandbox Code Playgroud)

我发现了另一篇文章,他们使用“fs”在证书中读取内容,如下所示。

const config = {
database: 'database-name',
host: 'host-or-ip',
user: 'username',
password: 'password',
port: 1234,
// this object will be passed to the TLSSocket constructor
ssl: {
  ca: fs.readFileSync('/path/to/digitalOcean/certificate.crt').toString()
 }
}
Run Code Online (Sandbox Code Playgroud)

我无法做到这一点,因为我正在使用 git 来部署我的应用程序。特别是 Digital Oceans 新的应用程序平台。我曾尝试联系他们,但没有成功。我不想将我的证书提交到我的源代码管理中。看到很多帖子都建议设置

ssl : { …
Run Code Online (Sandbox Code Playgroud)

postgresql ssl node.js node-postgres digital-ocean

6
推荐指数
1
解决办法
7717
查看次数

标签 统计

digital-ocean ×1

node-postgres ×1

node.js ×1

postgresql ×1

ssl ×1