Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ const sql = postgres('postgres://username:password@host:port/database', {
database : '', // Name of database to connect to
username : '', // Username of database user
password : '', // Password of database user
ssl : false, // true, prefer, require, tls.connect options
ssl : false, // true, prefer, require, direct, tls.connect options
max : 10, // Max number of connections
max_lifetime : null, // Max lifetime in seconds (more info below)
idle_timeout : 0, // Idle connection timeout in seconds
Expand Down
20 changes: 19 additions & 1 deletion src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,11 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
if (options.socket)
return ssl ? secure() : connected()

socket.on('connect', ssl ? secure : connected)
if (ssl === 'direct') {
socket.on('connect', directTLS)
} else {
socket.on('connect', ssl ? secure : connected)
}

if (options.path)
return socket.connect(options.path)
Expand All @@ -349,6 +353,20 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
hostIndex = (hostIndex + 1) % port.length
}

function directTLS() {
socket.removeAllListeners()
socket = tls.connect({
socket,
servername: net.isIP(socket.host) ? undefined : socket.host,
ALPNProtocols: ['postgresql'],
rejectUnauthorized: false
})
socket.on('secureConnect', connected)
socket.on('error', error)
socket.on('close', closed)
socket.on('drain', drain)
}

function reconnect() {
setTimeout(connect, closedDate ? closedDate + delay - performance.now() : 0)
}
Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface BaseOptions<T extends Record<string, postgres.PostgresType>> {
* How to deal with ssl (can be a tls.connect option object)
* @default false
*/
ssl: 'require' | 'allow' | 'prefer' | 'verify-full' | boolean | object;
ssl: 'require' | 'allow' | 'prefer' | 'verify-full' | 'direct' | boolean | object;
/**
* Max number of connections
* @default 10
Expand Down