I’m looking at a business plan at this stage, and the only feature I need to confirm is this Host rewrite page rule feature before I take the plunge.
Does anyone know if it’s currently available with Business plans or not? I’m hesitant to take the $200 plunge just to find out it’s not possible.
No problem. This would be a handy way to ‘rewrite’ urls in many contexts not just S3.
Just replace with your S3 bucket, and likely also change the S3 endpoint as well.
I also alter the cache header as well on the response.
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
})
async function handleRequest(request) {
let path = new URL(request.url).pathname;
let response = await fetch("https://s3-ap-southeast-2.amazonaws.com/<bucket name>" + path, request);
response = new Response(response.body, response);
response.headers.set("Cache-Control", "public, s-max-age=14400, stale-while-revalidate=3600, stale-if-error=86400");
return response;
}