createFanoutHandoff

Functionin fanout@fastly/js-compute 4.0.0View source
createFanoutHandoff(request: Request, backend: string): Response

Creates a Response that instructs Fastly to pass the original request through Fanout to the declared backend.

Note: Can only be used when processing requests, not during build-time initialization.

Parameters

request: Request

The request to pass through Fanout.

backend: string

The name of the backend that Fanout should send the request to. The name must be between 1 and 254 characters inclusive.

Returns

Response

A Response that can be passed to event.respondWith.

Throws

  • Error if request is not a Request instance, or if backend is an empty string or longer than 254 characters.
1
2
3
4
5
6
7
8
9
10
11
import { createFanoutHandoff } from "fastly:fanout";
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 });
}
addEventListener("fetch", (event) => event.respondWith(handleRequest(event)));