new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Supabase · Edge Functions · all subjects

edge functions/websockets

7 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Disable JWT verification for WebSocket functions

To allow WebSocket functions to work without standard authorization header checks, use the --no-verify-jwt flag when serving and deploying functions.

WebSocket server creation with Deno

To create a WebSocket server in Deno, check if the request has an 'upgrade' header set to 'websocket', then call Deno.upgradeWebSocket(req) to get a socket object and response. The socket object has onopen, onmessage, onerror, and onclose event handlers. Return the response object to complete the upgrade.

WebSocket server creation with Node.js

To create a WebSocket server in Node.js, import createServer from 'node:http' and WebSocketServer from 'npm:ws@^8'. Create an HTTP server and WebSocketServer with noServer: true mode. Listen for 'upgrade' events on the server and call wss.handleUpgrade(req, socket, head, callback) to establish WebSocket connections.

Outbound WebSocket connections from Edge Functions

Edge Functions can establish outbound WebSocket connections to other servers, enabling use cases like WebSocket proxy servers or relay servers for external APIs such as the OpenAI Realtime API.

WebSocket browser clients cannot send custom headers

WebSocket browser clients do not have the ability to send custom headers, which prevents standard JWT authorization header checks from working.

Prevent early worker retirement with WebSockets

When using WebSockets, the HTTP request is considered complete after Deno.upgradeWebSocket(req) returns the response. To prevent early worker retirement while the socket is still open, keep an unresolved EdgeRuntime.waitUntil() promise that resolves in socket.onclose.

Resumable WebSockets for production

For production-ready WebSocket implementations with reconnect patterns, session persistence, and replay capabilities, use the Resumable WebSockets pattern with Edge Functions.

Give your agent this brain