let last_known_version = "1.2.2"; const api_root = "https://XXX.workers.dev/version/"; const x86_64_apple_darwin = api_root + "x86_64-apple-darwin"; const x86_64_unknown_linux_gnu = api_root + "x86_64-unknown-linux-gnu"; const x86_64_pc_windows_msvc = api_root + "x86_64-pc-windows-msvc"; const re_x86_64_apple_darwin = /href="\/denoland\/deno\/releases\/download\/v(.*?)\/deno-x86_64-apple-darwin.zip"/; const re_x86_64_unknown_linux_gnu = /href="\/denoland\/deno\/releases\/download\/v(.*?)\/deno-x86_64-unknown-linux-gnu.zip"/; const re_x86_64_pc_windows_msvc = /href="\/denoland\/deno\/releases\/download\/v(.*?)\/deno-x86_64-pc-windows-msvc.zip"/; addEventListener("fetch", event => { event.respondWith(handle_request(event.request)); }); async function handle_request(req) { let regex; switch (req.url) { case x86_64_apple_darwin: regex = re_x86_64_apple_darwin; break; case x86_64_unknown_linux_gnu: regex = re_x86_64_unknown_linux_gnu; break; case x86_64_pc_windows_msvc: regex = re_x86_64_pc_windows_msvc; break; default: return new Response("", { status: 404 }); } const res = await fetch("https://github.com/denoland/deno/releases/"); if (!res.ok) { return new Reponse(last_known_version, { status: 200 }); } const text = await res.text(); const match = text.match(regex); if (match === null) { return new Reponse(last_known_version, { status: 200 }); } last_known_version = match[1]; return new Response(last_known_version, { status: 200 }); }