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
30 changes: 25 additions & 5 deletions types/fanout.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,34 @@

declare module 'fastly:fanout' {
/**
* Creates a {@link Response} that instructs Fastly to pass the original
* request through [Fanout](https://www.fastly.com/documentation/guides/concepts/real-time-messaging/fanout/)
* to the declared backend.
*
* @param request The request to pass through Fanout.
* **Note**: Can only be used when processing requests, not during build-time
* initialization.
*
* @example
* ```js
* import { createFanoutHandoff } from "fastly:fanout";
*
* The name of the backend that Fanout should send the request to.
* The name has to be between 1 and 254 characters inclusive.
* @param backend The name of the environment variable
* async function handleRequest(event) {
* const url = new URL(event.request.url);
* if (url.pathname === "/stream") {
* return createFanoutHandoff(event.request, "my-backend");
* }
* return new Response("Not found", { status: 404 });
* }
*
* @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.
* addEventListener("fetch", (event) => event.respondWith(handleRequest(event)));
* ```
*
* @param request The request to pass through Fanout.
* @param backend The name of the backend that Fanout should send the request
* to. The name must be between 1 and 254 characters inclusive.
* @returns A {@link Response} that can be passed to `event.respondWith`.
* @throws `Error` if `request` is not a {@link Request} instance, or
* if `backend` is an empty string or longer than 254 characters.
*/
function createFanoutHandoff(request: Request, backend: string): Response;
}
Loading