Skip to content

Instantly share code, notes, and snippets.

Created May 10, 2022 14:08
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
CloudFlare worker to rewrite Host header for S3
addEventListener('fetch', event => {
const lookup = {
"": "",
async function handleRequest(origRequest) {
const origUrl = new URL(origRequest.url);
const newOrigin = lookup[origUrl.hostname];
let request = origRequest;
if (newOrigin) {
const newUrl = origRequest.url.replace(origUrl.origin, newOrigin);
request = new Request(newUrl, {
body: origRequest.body,
headers: origRequest.headers,
method: origRequest.method,
redirect: origRequest.redirect
const response = await fetch(request);
// console.log({ response });
return response;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment