The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat(examples): streams edge function
Greg Richardson55459584465f
diff --git a/examples/edge-functions/supabase/functions/streams/README.md b/examples/edge-functions/supabase/functions/streams/README.mdnew file mode 100644index 00000000000..52cd230a364--- /dev/null+++ b/examples/edge-functions/supabase/functions/streams/README.md@@ -0,0 +1,19 @@+# streams++## Run locally++```bash+supabase functions serve --no-verify-jwt streams+```++Use cURL or Postman to make a GET request to http://localhost:54321/functions/v1/streams.++```bash+curl http://localhost:54321/functions/v1/streams+```++## Deploy++```bash+supabase functions deploy --no-verify-jwt streams+```diff --git a/examples/edge-functions/supabase/functions/streams/index.ts b/examples/edge-functions/supabase/functions/streams/index.tsnew file mode 100644index 00000000000..15d3c2ace8e--- /dev/null+++ b/examples/edge-functions/supabase/functions/streams/index.ts@@ -0,0 +1,26 @@+import { serve } from 'https://deno.land/[email protected]/http/server.ts'++const msg = new TextEncoder().encode('data: hello\r\n\r\n')++serve((_) => {+ let timerId: number | undefined++ const body = new ReadableStream({+ start(controller) {+ timerId = setInterval(() => {+ controller.enqueue(msg)+ }, 1000)+ },+ cancel() {+ if (typeof timerId === 'number') {+ clearInterval(timerId)+ }+ },+ })++ return new Response(body, {+ headers: {+ 'Content-Type': 'text/event-stream',+ },+ })+})