Forked from noamr/gist:c9efc56220820d5dd716eb6f64c11146
Created
November 27, 2022 09:21
-
-
Save perjerz/da0964ba180dc5c680a59fb6656f6f3a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const TMDB_IMAGE_BASE_URL = 'https://image.tmdb.org/t/p/'; | |
addEventListener("fetch", e => { | |
const url = new URL(e.request.url); | |
if (url.pathname === "/image") { | |
e.respondWith((async () => { | |
const width = url.searchParams.get("width"); | |
const path = url.searchParams.get("path"); | |
try { | |
return await fetch(`${TMDB_IMAGE_BASE_URL}/w${width}${path}`, {mode: "no-cors"}); | |
} catch (e) { | |
return Response.redirect("/nothing.svg"); | |
} | |
})()); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment