addEventListener("fetch", (event) => event.respondWith(handleRequest(event)));

async function handleRequest(event) {
  let req = event.request;

  // Set logger
  const logger = fastly.getLogger("logtest");

  // Send request to origin_0 and origin_1
  const [backendResponse, tbackendResponse] = await Promise.all([
    fetch(req, {
      backend: "origin_0"
    }),
    fetch(req, {
      backend: "origin_1"
    })
  ]);

  // Set status code and content-length of each backend response
  const prodresult = backendResponse.statusText + " " + backendResponse.headers.get("content-length");
  const testresult = tbackendResponse.statusText + " " + tbackendResponse.headers.get("content-length");

  // Evaluate prod and test result and log
  if (prodresult != testresult) {
    logger.log(
      "The production and test environments returned different content"
    );
  } else {
    logger.log("Prod and test are the same");
  }
  return backendResponse;
}