Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
petebacondarwin committed Jun 10, 2024
1 parent 33a2e7e commit e2aa8fb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/pg/lib/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@ module.exports.getSecureStream = function getSecureStream(options) {
* @returns true if the code is currently running inside a Cloudflare Worker.
*/
function computeIsCloudflareRuntime() {
console.log('computeIsCloudflareRuntime')
process.env.TESTXXX && console.log('computeIsCloudflareRuntime')
// Since 2022-03-21 the `global_navigator` compatibility flag is on for Cloudflare Workers
// which means that `navigator.userAgent` will be defined.
if (typeof navigator === 'object' && navigator !== null && typeof navigator.userAgent === 'string') {
console.log('navigator.userAgent', navigator.userAgent)
process.env.TESTXXX && console.log('navigator.userAgent', navigator.userAgent)
return navigator.userAgent === 'Cloudflare Workers'
}
// In case `navigator` or `navigator.userAgent` is not defined then try a more sneaky approach
if (typeof Response === 'function') {
const resp = new Response(null, { cf: { thing: true } })
console.log('Response object', typeof resp.cf === 'object' && resp.cf !== null && resp.cf.thing)
process.env.TESTXXX &&
console.log('Response object', typeof resp.cf === 'object' && resp.cf !== null && resp.cf.thing)
if (typeof resp.cf === 'object' && resp.cf !== null && resp.cf.thing) {
return true
}
Expand Down
2 changes: 2 additions & 0 deletions packages/pg/test/worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export interface Env {
PGPASSWORD: string
}

process.env.TESTXXX = true

export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
const url = new URL(request.url)
Expand Down

0 comments on commit e2aa8fb

Please sign in to comment.