123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- const { getStream, getSecureStream } = getStreamFuncs()
- module.exports = {
-
- getStream,
-
- getSecureStream,
- }
- function getNodejsStreamFuncs() {
- function getStream(ssl) {
- const net = require('net')
- return new net.Socket()
- }
- function getSecureStream(options) {
- var tls = require('tls')
- return tls.connect(options)
- }
- return {
- getStream,
- getSecureStream,
- }
- }
- function getCloudflareStreamFuncs() {
- function getStream(ssl) {
- const { CloudflareSocket } = require('pg-cloudflare')
- return new CloudflareSocket(ssl)
- }
- function getSecureStream(options) {
- options.socket.startTls(options)
- return options.socket
- }
- return {
- getStream,
- getSecureStream,
- }
- }
- function isCloudflareRuntime() {
-
-
- if (typeof navigator === 'object' && navigator !== null && typeof navigator.userAgent === 'string') {
- return navigator.userAgent === 'Cloudflare-Workers'
- }
-
- if (typeof Response === 'function') {
- const resp = new Response(null, { cf: { thing: true } })
- if (typeof resp.cf === 'object' && resp.cf !== null && resp.cf.thing) {
- return true
- }
- }
- return false
- }
- function getStreamFuncs() {
- if (isCloudflareRuntime()) {
- return getCloudflareStreamFuncs()
- }
- return getNodejsStreamFuncs()
- }
|