export default {
async fetch(request) {
// Define fetch options to follow redirects
const fetchOptions = {
redirect: "follow", // Ensure fetch follows redirects automatically. Each subrequest in a redirect chain counts against the subrequest limit.
};
// Make the fetch request to the origin
const response = await fetch(request, fetchOptions);
// Log the final URL after redirects (optional, for debugging)
console.log(`Final URL after redirects: ${response.url}`);
// Return the final response to the client
return response;
},
};このテンプレートはそのまま使え、ほとんどのリダイレクト追跡の用途に向いています。
Snippets は、オリジンサーバーが返すリダイレクトを透過的にたどります。Fetch API の redirect: "follow" オプションにより、3xx リダイレクトは自動処理され、最終レスポンスが返ります。オリジンのレスポンスがリダイレクトでなければ、元の内容が返ります。