# sub3 example on Cloudflare Workers The [Node example](../node/README.md) as a Worker, against the **sub3 sandbox** (Arc Testnet, free test USDC). The routes are the same file (`../node/app.mjs`); the pages are `../node/public`; the ledger is the SQLite of one Durable Object per environment and product, so receipts are credited once and credits are never spent twice. | File | What it does | | ---------------- | -------------------------------------------------------------------------------------------------- | | `wrangler.jsonc` | Static pages from `../node/public`; `/api/*` and `/.well-known/sub3.json` go to the Worker; vars | | `worker.mjs` | Sends those requests to the `Ledger` Durable Object, which runs `createApp` on `ledgerOn(storage)` | ## Deploy 1. Create your merchant and product **on the sandbox** (https://sandbox.sub3.dev/dashboard, or the CLI with `SUB3_ENVIRONMENT=sandbox`). 2. Set `SUB3_PRODUCT` and `APP_ORIGIN` (your Worker's `https://…workers.dev` origin, exactly) in `wrangler.jsonc`. If your item keys differ from `basic`/`pro`/`forever`, edit `../node/config.mjs`. 3. Deploy: ```sh cd examples/cloudflare npm run setup # installs wrangler here and jose in ../node npx wrangler login npm run deploy ``` 4. Show your logo at checkout: set the merchant's website to the Worker and check it, `node sub3.mjs merchant set --url https://sub3-example..workers.dev` then `node sub3.mjs verify `. Replace `../node/public/logo.svg` with your own. `npm run dev` runs it locally (`wrangler dev`). For production, set `SUB3_ENVIRONMENT` to `production` with a production product; sandbox and production never share purchases. One Durable Object serves every user of the product: simple and strictly consistent, and enough for a demo or a small app. For heavy traffic, use one Durable Object per user (`idFromName(user)`), since each user's receipts, credits and allowance are independent.