Skip to content

Instantly share code, notes, and snippets.

@patryk
Created March 12, 2020 13:35
Show Gist options
  • Save patryk/f570d1a98e45f0ddec76f95b3706ffdb to your computer and use it in GitHub Desktop.
Save patryk/f570d1a98e45f0ddec76f95b3706ffdb to your computer and use it in GitHub Desktop.
Worker subdomain to S3 path
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
/**
* Respond to the request
* @param {Request} request
*/
async function handleRequest(request) {
let url = new URL(request.url)
let subdomain = url.hostname.split('.')[0]
url.hostname = 's3-eu-west-1.amazonaws.com'
url.pathname = 'bucket-2324324242' + '/' + subdomain + '/' + url.pathname
return fetch(url, request)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment