const backends = ["origin_0", "origin_1"];
addEventListener("fetch", event => {
// Get the request from the client.
const req = event.request;
// Pick which origin to use as a backend randomly.
const randomBackend = backends[Math.floor(Math.random() * backends.length)];
// Send the request to a random backend.
const backendResponse = fetch(req, {
backend: randomBackend
});
// Send the backend response back to the client.
event.respondWith(backendResponse);
});