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 a6099dd
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/pg/lib/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
* @returns {Duplex}
*/
module.exports.getStream = function getStream(ssl) {
try {
const { CloudflareSocket } = require('pg-cloudflare')
return new CloudflareSocket(ssl)
} catch {
console.log(process?.release?.name)
if (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 +19,12 @@ 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?.name === 'node') {
var tls = require('tls')
return tls.connect(options)
}

Check failure on line 25 in packages/pg/lib/stream.js

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎·`

Check failure on line 25 in packages/pg/lib/stream.js

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎·`
else {
options.socket.startTls(options)
return options.socket
}
}

0 comments on commit a6099dd

Please sign in to comment.