Skip to content

Commit

Permalink
Include SSL configuration to work around issue with self-signed certs (
Browse files Browse the repository at this point in the history
  • Loading branch information
nielssj committed Jan 18, 2022
1 parent a4892c9 commit fdc90a9
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/index.js
Expand Up @@ -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);
});
Expand Down

0 comments on commit fdc90a9

Please sign in to comment.