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); });