Created
March 12, 2020 13:35
-
-
Save patryk/f570d1a98e45f0ddec76f95b3706ffdb to your computer and use it in GitHub Desktop.
Worker subdomain to S3 path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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