examples/storefront Public
# storefrontThe API behind a small online shop, running on Cloudflare Workers. Products, carts and orders live in D1, product images in R2.It is a plain fetch handler with a small router, no framework, and the tests run the real SQL migrations on Node's built-in SQLite, so `npm test` needs nothing but Node 24.## Running it```bashnpm installnpm testnpm run typecheck```To run the Worker locally:```bashnpx wrangler d1 migrations apply storefront --localecho 'ADMIN_TOKEN=dev-admin-token' > .dev.varsnpm run dev```Then add a product and look at the catalog:```bashcurl -X PUT localhost:8787/admin/products/wool-socks \ -H 'authorization: Bearer dev-admin-token' -H 'content-type: application/json' \ -d '{"name":"Wool socks","price_cents":1800,"stock":40}'curl localhost:8787/products```## API| Method and path | What it does || --- | --- || `GET /products` | Active products, by name || `GET /products/:id` | One active product || `PUT /admin/products/:id` | Create or replace a product (admin token) || `PUT /admin/products/:id/image` | Upload the product's image (admin token) || `GET /images/<key>` | A product image || `POST /carts` | A new, empty cart || `GET /carts/:id` | A cart with its lines and totals || `PUT /carts/:id/items/:product` | Set a quantity, `{ "quantity": n }` || `DELETE /carts/:id/items/:product` | Remove a line |Errors are JSON, `{ "error": "<code>", "message": "..." }`, with extra fields where they help (an `out_of_stock` error says how many are `available`).## Layout```src/ storefront-api: router, catalog, carts, imagesmigrations/ D1 schema, applied in ordertest/ node --test suites and the D1 and R2 stand-ins.rebasely/ architecture map, knowledge base and CI workflow```The knowledge base in `.rebasely/kb` explains how each part works and why; start at its index.## LicenseMIT