Created
June 22, 2022 04:40
-
-
Save PatelUtkarsh/0438735990e0b6f373b4deaf7f9be277 to your computer and use it in GitHub Desktop.
Cloudflare worker proxy object storage image
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)) | |
}) | |
async function handleRequest(request) { | |
const hiddenImageOrigin = "s3 url without trailing shash" | |
const requestURL = new URL(request.url) | |
// Append the request path such as "/assets/image1.jpg" to the hiddenImageOrigin. | |
// You could also process the path to add or remove directories, modify filenames, etc. | |
const imageURL = hiddenImageOrigin + requestURL.pathname; | |
// This will fetch image from the given URL, but to the website's visitors this | |
// will appear as a response to the original request. Visitor’s browser will | |
// not see this URL. | |
return fetch(imageURL) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment