Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perjerz/da0964ba180dc5c680a59fb6656f6f3a to your computer and use it in GitHub Desktop.
Save perjerz/da0964ba180dc5c680a59fb6656f6f3a to your computer and use it in GitHub Desktop.
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