Publishing service

Ara Play's Publish online button needs a small publishing service in two parts, both on free plans: a Cloudflare Worker that does almost all the work, and one account step as a Vercel function. Cloudflare refuses to create temporary accounts for requests coming from any Worker (worker_subrequest_blocked), and its API doesn't accept requests from web pages, so that single request runs on a server outside Cloudflare.

Players' games don't go into your account. Each one goes into a temporary Cloudflare account created for that player, which they can claim within 60 minutes. Cloudflare deletes unclaimed accounts. See Cloudflare's claim deployments for the platform side.

Why there is a service

Cloudflare's provisioning and upload API can't be called from a web page, and each temporary account's API token must not reach the browser. The service relays each step and keeps that token encrypted inside an opaque session that the browser carries between requests. It stores nothing. Both parts run the same code (src/publish-service/) and share SESSION_SECRET, so a session sealed by the account step opens on the Worker.

Step What the service does
POST /v1/challenge Fetches Cloudflare's proof-of-work challenge. The player's browser solves it in a background thread: about 16 million SHA-256 hashes, a few seconds.
POST /v1/account Runs on Vercel. Checks the game's project.json, then creates the temporary account and returns the sealed session and the claim link.
POST /v1/manifest Checks the file list and opens Cloudflare's asset upload session.
POST /v1/upload Streams one batch of files to Cloudflare.
POST /v1/finish Uploads the fixed game server script, attaches the files and turns on the game's workers.dev address.

Guardrails

Deploy

  1. Deploy the Worker with your Cloudflare account:

    npm run publish:deploy
    

    Wrangler prints its address, for example https://ara-publish.<your-subdomain>.workers.dev.

  2. Create the shared settings in publish/vercel/.env.deploy (kept out of git): a SESSION_SECRET of 32 or more random characters, and ALLOWED_ORIGINS listing the pages that host Ara Play, comma-separated.

  3. Give the Worker the same secret:

    grep '^SESSION_SECRET=' publish/vercel/.env.deploy | cut -d= -f2- | tr -d '\n' | npx wrangler@4 secret put SESSION_SECRET -c publish/wrangler.jsonc
    
  4. Build the account step and deploy it to Vercel. The first deploy signs you in and creates the project (accept the folder as it is); then add both settings for Production, using the values from .env.deploy, and deploy again so they take effect:

    npm run publish:build-account
    cd publish/vercel
    npx vercel@latest deploy --prod
    npx vercel@latest env add SESSION_SECRET production
    npx vercel@latest env add ALLOWED_ORIGINS production
    npx vercel@latest deploy --prod
    

    It runs as an ordinary Node function, not on Vercel's edge network.

  5. Put both addresses in .env at the repository root, which every build reads:

    VITE_PUBLISH_URL=https://ara-publish.<your-subdomain>.workers.dev
    VITE_PUBLISH_ACCOUNT_URL=https://<your-vercel-project>.vercel.app
    

    Without VITE_PUBLISH_URL, the button explains that publishing isn't set up and points players to Download game ZIP. Local development can publish too: http://localhost:* in ALLOWED_ORIGINS allows any localhost port.

Changing SESSION_SECRET means setting it on both hosts; publishes already in progress then fail and the player starts again.

Tests

npm run test:publish runs the guard, file splitting, the game server's joining and byte ranges, the whole service flow against a stand-in Cloudflare API (including every refusal and a check that the account token never reaches the browser), and the colour themes. npm run test:play:browser -- --publish runs the dialog in a browser against the real service code with a stand-in Cloudflare API.