Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions types/websocket.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,30 @@

declare module 'fastly:websocket' {
/**
* Create a {@link Response} that instructs Fastly to pass the original request through as a
* WebSocket connection to the specified backend.
*
* @param request The request to pass through Websocket.
* **Note**: Can only be used when processing requests, not during build-time initialization.
*
* The name of the backend that Websocket should send the request to.
* The name has to be between 1 and 254 characters inclusive.
* @param backend The name of the environment variable
* @example
* ```js
* import { createWebsocketHandoff } from "fastly:websocket";
*
* @throws {TypeError} Throws a TypeError if the backend is not valid. I.E. The backend is null, undefined, an empty string or a string with more than 254 characters.
* async function handleRequest(event) {
* const url = new URL(event.request.url);
* if (url.pathname === '/stream') {
* return createWebsocketHandoff(event.request, 'websocket-backend');
* }
* return new Response('Not found', { status: 404 });
* }
*
* addEventListener("fetch", (event) => event.respondWith(handleRequest(event)));
* ```
*
* @param request The request to pass through as a WebSocket connection
* @param backend The name of the backend to send the request to (1–254 characters)
* @throws Throws an `Error` if `request` is not a {@link Request} instance, or if `backend` is empty or longer than 254 characters
* @version 3.34.0
*/
function createWebsocketHandoff(request: Request, backend: string): Response;
}
Loading