Skip to content

Instantly share code, notes, and snippets.

@filiptronicek
Created October 27, 2020 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filiptronicek/f1a357b089eee0e541180a570e126805 to your computer and use it in GitHub Desktop.
Save filiptronicek/f1a357b089eee0e541180a570e126805 to your computer and use it in GitHub Desktop.
Minecraft latest version Cloudflare Worker
const url = "https://launchermeta.mojang.com/mc/game/version_manifest.json";
async function gatherResponse(response) {
const { headers } = response;
const contentType = headers.get("content-type") || "";
return (await response.json());
}
async function handleRequest() {
const init = {
headers: {
"content-type": "application/json;charset=UTF-8",
},
};
const response = await fetch(url, init);
const results = await (gatherResponse(response));
const newestversion = results.versions[0].url;
const newestVersionResponce = await fetch(newestversion, init)
const newestVersionResult = await gatherResponse(newestVersionResponce);
const newestVersionURL = newestVersionResult.downloads.server.url;
return Response.redirect(newestVersionURL, 301)
}
addEventListener("fetch", (event) => {
return event.respondWith(handleRequest());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment