Skip to content

Commit

Permalink
fix: Revert "fix: use @supabase/node-fetch"
Browse files Browse the repository at this point in the history
This reverts commit f290bb3.
  • Loading branch information
soedirgo committed Aug 28, 2023
1 parent f290bb3 commit ae31b44
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 46 deletions.
39 changes: 17 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"homepage": "https://github.com/supabase/functions-js#readme",
"dependencies": {
"@supabase/node-fetch": "^2.6.13"
"cross-fetch": "^3.1.5"
},
"devDependencies": {
"@types/jest": "^28.1.0",
Expand Down
3 changes: 1 addition & 2 deletions src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ export const resolveFetch = (customFetch?: Fetch): Fetch => {
if (customFetch) {
_fetch = customFetch
} else if (typeof fetch === 'undefined') {
_fetch = (...args) =>
import('@supabase/node-fetch' as any).then(({ default: fetch }) => fetch(...args))
_fetch = async (...args) => await (await import('cross-fetch')).fetch(...args)
} else {
_fetch = fetch
}
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export type FunctionInvokeOptions = {
/**
* The HTTP verb of the request
*/
method?: "POST" | "GET" | "PUT" | "PATCH" | "DELETE"
method?: "POST"| "GET"| "PUT" | "PATCH" | "DELETE"
/**
* The body of the request.
*/
Expand Down
30 changes: 16 additions & 14 deletions test/functions/hijack/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { serve } from 'https://deno.land/[email protected]/http/server.ts'

serve((req) => {
const p = Deno.upgradeHttp(req)

// Run this async IIFE concurrently, first packet won't arrive
// until we return HTTP101 response.
;(async () => {
const [conn, firstPacket] = await p
const decoder = new TextDecoder()
const text = decoder.decode(firstPacket)
console.log(text)
// Hello
const uint8Array = new Uint8Array([72, 101, 108, 108, 111])
conn.write(uint8Array)
conn.close()
})()
const p = Deno.upgradeHttp(req);

(
// Run this async IIFE concurrently, first packet won't arrive
// until we return HTTP101 response.
async () => {
const [conn, firstPacket] = await p
const decoder = new TextDecoder()
const text = decoder.decode(firstPacket)
console.log(text)
// Hello
const uint8Array = new Uint8Array([72, 101, 108, 108, 111])
conn.write(uint8Array)
conn.close()
}
)()

// HTTP101 - Switching Protocols
return new Response(null, { status: 101 })
Expand Down
5 changes: 2 additions & 3 deletions test/relay/container.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as fs from 'fs'
import { nanoid } from 'nanoid'
// @ts-ignore
import nodeFetch from '@supabase/node-fetch'
import crossFetch from 'cross-fetch'
import { sign } from 'jsonwebtoken'
import { GenericContainer, Network, StartedTestContainer, Wait } from 'testcontainers'
import { ExecResult } from 'testcontainers/dist/docker/types'
Expand Down Expand Up @@ -88,7 +87,7 @@ export async function runRelay(
log(`check function is healthy: ${slug + '-' + id}`)
for (let ctr = 0; ctr < 30; ctr++) {
try {
const healthCheck = await nodeFetch(
const healthCheck = await crossFetch(
`http://localhost:${startedRelay.getMappedPort(8081)}/${slug}`,
{
method: 'POST',
Expand Down
5 changes: 2 additions & 3 deletions test/utils/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @ts-ignore
import nodeFetch from '@supabase/node-fetch'
import crossFetch from 'cross-fetch'

/**
* It returns a crossFetch function that uses overridden input: RequestInfo and init?: RequestInit for
Expand All @@ -12,5 +11,5 @@ export function getCustomFetch(
reqInfo: RequestInfo | URL,
reqInit?: RequestInit | undefined
): (input: RequestInfo | URL, init?: RequestInit | undefined) => Promise<Response> {
return (input, init) => nodeFetch(reqInfo, reqInit)
return (input, init) => crossFetch(reqInfo, reqInit)
}

0 comments on commit ae31b44

Please sign in to comment.