Skip to content

Commit ea7f7e3

Browse files
committed
PostgreSQL client: support $PGSSLROOTCERT env var
This is a shim for brianc/node-postgres#2723.
1 parent fd593d0 commit ea7f7e3

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/db.js

+14
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1+
import {ok} from 'node:assert'
2+
import {readFileSync} from 'node:fs'
13
import _pg from 'pg'
24
const {Pool} = _pg
35

6+
const ssl = {}
7+
// pg doesn't support $PGSSLROOTCERT yet, so we pass it in ourselves
8+
// see https://github.com/brianc/node-postgres/issues/2723
9+
if ('PGSSLROOTCERT' in process.env) {
10+
ok(process.env.PGSSLROOTCERT, '$PGSSLROOTCERT must not be empty')
11+
ssl.ca = readFileSync(process.env.PGSSLROOTCERT, {encoding: 'utf8'})
12+
}
13+
414
const connectToPostgres = (opt = {}) => {
515
// todo?
616
// > Do not use pool.query if you need transactional integrity: the pool will dispatch every query passed to pool.query on the first available idle client. Transactions within PostgreSQL are scoped to a single client and so dispatching individual queries within a single transaction across multiple, random clients will cause big problems in your app and not work. For more info please read transactions.
717
// https://node-postgres.com/api/pool
818
const db = new Pool({
919
...opt,
20+
ssl: {
21+
...ssl,
22+
...(opt.ssl || {}),
23+
},
1024
// todo: let this depend on the configured matching parallelism
1125
max: parseInt(process.env.PG_POOL_SIZE || '30'),
1226
})

0 commit comments

Comments
 (0)