createFanoutHandoff
The createFanoutHandoff()
function creates a Response instance which informs Fastly to pass the original Request through Fanout, to the declared backend.
Syntax
createFanoutHandoff(request, backend)
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 has to be between 1 and 254 characters inclusive.
- Throws a
TypeError
if the value is not valid. I.E. The value is null, undefined, an empty string or a string with more than 254 characters.
Return value
A Response instance is returned, which can then be used via event.respondWith
.
Examples
In this example application requests to the path /stream
and sent handled via Fanout.
import { createFanoutHandoff } from "fastly:fanout";
async function handleRequest(event) {
try {
const url = new URL(event.request.url);
if (url.pathname === '/stream') {
return createFanoutHandoff(event.request, 'fanout');
} else {
return new Response('oopsie, make a request to /stream for some fanout goodies', { status: 404 });
}
} catch (error) {
console.error({error});
return new Response(error.message, {status:500})
}
}
addEventListener("fetch", (event) => event.respondWith(handleRequest(event)));