Skip to content

Commit 5396f1e

Browse files
authored
DB SSL config: allow unauthorized ssl connections (#85)
Co-authored-by: Stefano Ricci <SteRiccio@users.noreply.github.com>
1 parent 843ac0f commit 5396f1e

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/db/db.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ const pgp = pgPromise(initOptions)
2727
// 1114 is OID for timestamp in Postgres
2828
pgp.pg.types.setTypeParser(1114, (str: string) => new Date(`${str} GMT`))
2929

30+
// SSL connection configuration
31+
const sslConfig = ProcessEnv.pgSsl ? { rejectUnauthorized: !ProcessEnv.pgSslAllowUnauthorized } : false
32+
3033
const configCommon = {
3134
// How long a client is allowed to remain idle before being closed
3235
idleTimeoutMillis: 30000,
3336
// Max number of clients in the pool
3437
max: 30,
35-
// Whether to use ssl connections
36-
ssl: ProcessEnv.pgSsl,
38+
ssl: sslConfig,
3739
}
3840

3941
const config = ProcessEnv.dbUrl

src/processEnv/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const ProcessEnv = {
2626
pgPort: Number(pgPort),
2727
pgDatabase,
2828
pgSsl: process.env.PGSSL === 'true',
29+
pgSslAllowUnauthorized: process.env.PGSSL_ALLOW_UNAUTHORIZED === 'true',
2930
disableDbMigrations: process.env.DISABLE_DB_MIGRATIONS === 'true',
3031

3132
// Express

0 commit comments

Comments
 (0)