All Projects → astei → crafthead

astei / crafthead

Licence: MIT license
Super scalable Minecraft avatar generation, built on Cloudflare Workers

Programming Languages

typescript
32286 projects
rust
11053 projects
HTML
75241 projects
CSS
56736 projects
shell
77523 projects

Projects that are alternatives of or similar to crafthead

cfworker-url-shortener
部署在 Cloudflare Workers 的短网址服务
Stars: ✭ 52 (-22.39%)
Mutual labels:  cloudflare-workers
ethtools
A collection of useful tools for Ethereum users and developers alike
Stars: ✭ 83 (+23.88%)
Mutual labels:  cloudflare-workers
workers-react-pwa-example
No description or website provided.
Stars: ✭ 80 (+19.4%)
Mutual labels:  cloudflare-workers
activities
Discord slash command bot for opening voice channel activities, using Cloudflare Workers
Stars: ✭ 595 (+788.06%)
Mutual labels:  cloudflare-workers
DNS-over-Discord
A 1.1.1.1 DNS resolver built for Discord
Stars: ✭ 228 (+240.3%)
Mutual labels:  cloudflare-workers
doh-cf-workers
DNS-over-HTTPS proxy on Cloudflare Workers
Stars: ✭ 103 (+53.73%)
Mutual labels:  cloudflare-workers
Graphql Starter
💥 Monorepo template (seed project) pre-configured with GraphQL API, PostgreSQL, React, Relay, and Material UI.
Stars: ✭ 3,377 (+4940.3%)
Mutual labels:  cloudflare-workers
slshx
⚔️ Strongly-typed Discord commands on Cloudflare Workers
Stars: ✭ 163 (+143.28%)
Mutual labels:  cloudflare-workers
blog
🗃 Blog built with Remix, deployed to Cloudflare workers
Stars: ✭ 27 (-59.7%)
Mutual labels:  cloudflare-workers
workers-unsplash-api
Serverless API for requesting images from Unsplash's API, designed for use with a React frontend
Stars: ✭ 20 (-70.15%)
Mutual labels:  cloudflare-workers
cloudflare-worker-router
A super lightweight router (1.3K) with middleware support and ZERO dependencies for CloudFlare Workers.
Stars: ✭ 144 (+114.93%)
Mutual labels:  cloudflare-workers
Portfolio-Website
Vishesh's Portfolio Website
Stars: ✭ 47 (-29.85%)
Mutual labels:  cloudflare-workers
remix-guide
A platform for sharing everything about Remix
Stars: ✭ 197 (+194.03%)
Mutual labels:  cloudflare-workers
raposas
Diretório oficial do código do indexador Raposas.
Stars: ✭ 31 (-53.73%)
Mutual labels:  cloudflare-workers
IPFS PHOTO SHARE
💰用甚嚒服务器,ServerLess搭建一个图片分享站点!| 基于CloudFlareWorker无服务器函数和IPFS去中心化存储的图片分享网站
Stars: ✭ 76 (+13.43%)
Mutual labels:  cloudflare-workers
Wrangler
🤠 wrangle your Cloudflare Workers
Stars: ✭ 2,632 (+3828.36%)
Mutual labels:  cloudflare-workers
awesome-cloudflare-workers
😎 Awesome Cloudflare Workers
Stars: ✭ 335 (+400%)
Mutual labels:  cloudflare-workers
workers-pubsub
Google Pub/Sub API for Cloudflare Workers (and Node.js)
Stars: ✭ 25 (-62.69%)
Mutual labels:  cloudflare-workers
parsed-html-rewriter
A DOM-based implementation of Cloudflare Worker's HTMLRewriter.
Stars: ✭ 34 (-49.25%)
Mutual labels:  cloudflare-workers
reader
get a reader mode sharable url for any url - built with cloudflare workers https://reader.tuananh.net
Stars: ✭ 24 (-64.18%)
Mutual labels:  cloudflare-workers

Crafthead

Crafthead is a highly scalable, serverless Minecraft avatar rendering solution built on Cloudflare Workers. It runs on any of Cloudflare's 200+ datacenters worldwide with minimal latency.

Note: if you're a causal browser and wound up here, you probably want to go to Crafthead.net, the public instance of Crafthead I run.

Features

  • Extremely fast
  • Supports UUID fetching (dashed or not dashed) and username lookups
  • Renders avatars from 8px to 300px

Overall breakdown

Crafthead is split into two primary components: the request handler frontend, written in TypeScript, and the image generation logic, written in Rust and invoked by TypeScript by way of WebAssembly. This means it is possible to use Crafthead's image generation from within the browser, provided you had another method of loading the skins from the browser. However, the most convenient way to use Crafthead is to use the publicly-hosted instance that does the rendering on Cloudflare's extensive edge network.

The request handler (located under the worker directory) receives every request to Crafthead. It first parses each request to figure out what it is asking for. If Crafthead can't determine what the request is, it will use Cloudflare Workers Sites to serve the index page or a 404 page. Once it has determined what is to be retrieved (and misses the top-level cache), each request is "normalized" (essentially, this entails changing all username requests to use UUIDs instead) and the skin is looked up (all stages of this are cached in Workers KV and in the local cache for speed).

Skin and profile requests are fully serviced by the TypeScript request handler, however if an avatar, helm, or cube render (with others TBD) are requested, the skin, size, and render request are passed to the image generation logic written in Rust (located in src). The Rust component determines what is to be rendered, loads the skin's PNG using the image crate, renders the desired image (using the primitives of the image crate and the 1mageproc crate), saves the PNG into memory, and returns it to the TypeScript request handler to be sent to the client. This is why Crafthead requires a paid Cloudflare Workers plan: image handling is computationally expensive, and the 10ms CPU limit is insufficient for all but the smallest requests.

Rolling your own

Step 1: Reconsider

Use the public instance I've made available. You don't have to pay a single dime for it. I pick up all the costs. Plus, if you use it, you get speedy performance all the time since it is more likely my instance will be available to run immediately compared to yours.

If, on the other hand, you're looking to hack on Crafthead, then keep reading.

Step 2: You want to do it?

You will need to have the following:

  • A paid Cloudflare Workers plan. The Worker can be Bundled or Unbound, though the production setup is anticipated to be on the Unbound plan in the future. This is because Crafthead uses Workers KV and can easily exceed the CPU limits on the free plan.
  • The wrangler CLI.
  • Node.js.
  • Rust.
  • wasm-pack.

Then:

  • Copy wrangler.toml.dev to wrangler.toml and fill in your own account_id.
  • Run wrangler kv:namespace create CRAFTHEAD_PROFILE_CACHE and replace the kv_namespaces section in your configuration with the output from the command.
  • Use yarn install to install all the development dependencies
  • Use wrangler publish. You're done!

Notes on wrangler preview

If you're looking to test Crafthead using wrangler preview or wrangler dev, you should use the special-cased usernames MHF_Steve and char, which return the default "Steve" skin. If your code affects username lookups, however, you should consider deploying to workers.dev instead.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].