Sol*_*LLC 1 database postgresql ssl node.js digital-ocean
我使用 Nodejs 和 Express 编写 API。我的数据库遭到黑客攻击,我决定使用数字海洋管理数据库。Digital Ocean Managed 数据库需要 SSL,并且只为您提供一个 CA 证书。在所有教程中,SSL 需要 3 个文件。我没有找到任何关于如何仅使用一个文件连接 node-pg 的教程。我终于找到了解决方案,我想与社区分享。希望我能帮别人节省几个小时的挖掘时间。
Digital Ocean 为您提供的证书是根证书而不是客户端证书。在node-pgcert中指的是客户端证书,CA指的是根证书。CAoption 是应该使用的选项,而不是Cert.
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)
如果这个答案对您有用,请点赞,以便其他人也能找到它。
| 归档时间: |
|
| 查看次数: |
1087 次 |
| 最近记录: |