Skip to content

Commit fdc90a9

Browse files
authored
Include SSL configuration to work around issue with self-signed certs (brianc/node-postgres#2009)
1 parent a4892c9 commit fdc90a9

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/index.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,19 @@ class KeyvPostgres extends KeyvSql {
99
dialect: 'postgres',
1010
uri: 'postgresql://localhost:5432'
1111
}, opts);
12+
13+
// Add custom SSL configuration, if "sslmode" present in connectionString (Work around issue with self-signed certs: https://github.com/brianc/node-postgres/issues/2009)
14+
let ssl
15+
let connectionString = opts.uri
16+
const sslIndex = inputString.indexOf("sslmode")
17+
if (sslIndex > 0) {
18+
connectionString = connectionString.substring(0, sslIndex - 1)
19+
ssl = { rejectUnauthorized: false }
20+
}
1221

1322
opts.connect = () => Promise.resolve()
1423
.then(() => {
15-
const pool = new Pool({ connectionString: opts.uri });
24+
const pool = new Pool({ connectionString, ssl });
1625
return sql => pool.query(sql)
1726
.then(data => data.rows);
1827
});

0 commit comments

Comments
 (0)