From fdc90a969e940cc713b1a026c039812db82b3761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20S=C3=B8holm?= Date: Tue, 18 Jan 2022 11:09:21 +0100 Subject: [PATCH] Include SSL configuration to work around issue with self-signed certs (https://github.com/brianc/node-postgres/issues/2009) --- src/index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 08b9873..7828c1b 100644 --- a/src/index.js +++ b/src/index.js @@ -9,10 +9,19 @@ class KeyvPostgres extends KeyvSql { dialect: 'postgres', uri: 'postgresql://localhost:5432' }, opts); + + // Add custom SSL configuration, if "sslmode" present in connectionString (Work around issue with self-signed certs: https://github.com/brianc/node-postgres/issues/2009) + let ssl + let connectionString = opts.uri + const sslIndex = inputString.indexOf("sslmode") + if (sslIndex > 0) { + connectionString = connectionString.substring(0, sslIndex - 1) + ssl = { rejectUnauthorized: false } + } opts.connect = () => Promise.resolve() .then(() => { - const pool = new Pool({ connectionString: opts.uri }); + const pool = new Pool({ connectionString, ssl }); return sql => pool.query(sql) .then(data => data.rows); });