Skip to content

Commit

Permalink
fixup! refactor: tighten up cloudflare detection
Browse files Browse the repository at this point in the history
  • Loading branch information
petebacondarwin committed Mar 13, 2024
1 parent c5946f3 commit 079a259
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/pg/lib/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
* @returns {Duplex}
*/
module.exports.getStream = function getStream(ssl) {
try {
const { CloudflareSocket } = require('pg-cloudflare')
return new CloudflareSocket(ssl)
} catch {
if (process.release && process.release.name === 'node') {
const net = require('net')
return new net.Socket()
} else {
const { CloudflareSocket } = require('pg-cloudflare')
return new CloudflareSocket(ssl)
}
}

Expand All @@ -18,11 +18,11 @@ module.exports.getStream = function getStream(ssl) {
* @returns {Duplex}
*/
module.exports.getSecureStream = function getSecureStream(options) {
try {
options.socket.startTls(options)
return options.socket
} catch {
if (process.release && process.release.name === 'node') {
var tls = require('tls')
return tls.connect(options)
} else {
options.socket.startTls(options)
return options.socket
}
}

0 comments on commit 079a259

Please sign in to comment.