From 24ebbfd7d0873a0c01fe2861e14cf6afd22ad168 Mon Sep 17 00:00:00 2001 From: seveibar Date: Mon, 11 Jan 2021 09:28:05 -0500 Subject: [PATCH] fix: ssl not set up properly --- index.js | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index b487838..6b8c365 100644 --- a/index.js +++ b/index.js @@ -39,11 +39,6 @@ module.exports = ({ defaults.password || "", database, - ssl: process.env.POSTGRES_SSL - ? Boolean(process.env.POSTGRES_SSL) - : { - rejectUnauthorized: false, - }, } const createDatabase = async (dbName) => { @@ -52,6 +47,11 @@ module.exports = ({ client: "pg", connection: getConnectionInfo("postgres"), pool, + ssl: process.env.POSTGRES_SSL + ? Boolean(process.env.POSTGRES_SSL) + : { + rejectUnauthorized: false, + }, }) await conn.raw(`CREATE DATABASE ${dbName}`) await conn.destroy() @@ -64,6 +64,11 @@ module.exports = ({ client: "pg", connection: getConnectionInfo("postgres"), pool, + ssl: process.env.POSTGRES_SSL + ? Boolean(process.env.POSTGRES_SSL) + : { + rejectUnauthorized: false, + }, }) await conn.raw(`DROP DATABASE ${dbName}`) await conn.destroy() @@ -97,6 +102,11 @@ module.exports = ({ client: "pg", connection, pool, + ssl: process.env.POSTGRES_SSL + ? Boolean(process.env.POSTGRES_SSL) + : { + rejectUnauthorized: false, + }, }) // test connection @@ -113,7 +123,17 @@ module.exports = ({ if (user) { await pg.destroy() - pg = knex({ client: "pg", connection: getConnectionInfo(dbName), pool }) + pg = knex({ + client: "pg", + connection: getConnectionInfo(dbName), + pool, + + ssl: process.env.POSTGRES_SSL + ? Boolean(process.env.POSTGRES_SSL) + : { + rejectUnauthorized: false, + }, + }) await pg.raw(`SET ROLE ${user};`) // test connection try {