addEventListener("fetch", (event) => event.respondWith(handleRequest(event)));
async function handleRequest(event) {
let req = event.request;
const logger = fastly.getLogger("logtest");
const [backendResponse, tbackendResponse] = await Promise.all([
fetch(req, {
backend: "origin_0"
}),
fetch(req, {
backend: "origin_1"
})
]);
const prodresult = backendResponse.statusText + " " + backendResponse.headers.get("content-length");
const testresult = tbackendResponse.statusText + " " + tbackendResponse.headers.get("content-length");
if (prodresult != testresult) {
logger.log(
"The production and test environments returned different content"
);
} else {
logger.log("Prod and test are the same");
}
return backendResponse;
}