这是我第一次使用 NestJS,我无法将托管在 Digitalocean 上的 Postgres 数据库连接到 NestJS。
我在网上搜索解决方案并尝试添加 "ssl": "true"或 "extra": { "ssl": "true"}
这是我的 ormconfig.json
{
"type": "postgres",
"host": "host",
"port": "port",
"username": "username",
"password": "password",
"database": "database",
"extra": {
"ssl": "true"
},
"synchronize": "true",
"logging": "true",
"entities": ["src/**/*.entity.ts", "dist/**/*.entity.js"]
}
我希望它能连接到服务器。我遇到的错误是 [TypeOrmModule] Unable to connect to the database。错误:没有主机“”、用户“”、数据库“”、SSL 关闭的 pg_hba.conf 条目
如果有人有同样的问题,我通过为 ssl 添加一个字段并设置我从 Digital Ocean 获得的 ca 证书来修复它。这是我的 ormconfig 的样子:
module.exports = {
name: 'default',
type: 'postgres',
host: 'host',
port: port,
username: 'username',
password: 'password',
database: 'database',
synchronize: true,
dropSchema: false,
logging: true,
ssl: {
ca: process.env.SSL_CERT,
},
entities: ['src/**/*.entity.ts', 'dist/**/*.entity.js'],
};
我是一名优秀的程序员,十分优秀!