handleWebSocket
handleWebSocket(
request
,env
,_ctx
,options
):Promise
<Response
>
Defined in: packages/@livestore/sync-cf/src/cf-worker/worker.ts:101
Handles /websocket
endpoint.
Parameters
Section titled “Parameters”request
Section titled “request”Request
ExecutionContext
options
Section titled “options”durableObject?
Section titled “durableObject?”{ name?
: string
; }
durableObject.name?
Section titled “durableObject.name?”string
Needs to match the binding name from the wrangler config
Default
'WEBSOCKET_SERVER'
headers?
Section titled “headers?”HeadersInit
validatePayload?
Section titled “validatePayload?”(payload
) => void
| Promise
<void
>
Returns
Section titled “Returns”Promise
<Response
>
Example
Section titled “Example”const validatePayload = (payload: Schema.JsonValue | undefined) => { if (payload?.authToken !== 'insecure-token-change-me') { throw new Error('Invalid auth token') }}
export default { fetch: async (request, env, ctx) => { if (request.url.endsWith('/websocket')) { return handleWebSocket(request, env, ctx, { headers: {}, validatePayload }) }
return new Response('Invalid path', { status: 400, headers: corsHeaders }) }}
Throws
Section titled “Throws”If the payload is invalid