Deploy
If you want your own counter service under a custom domain, deploy Tally API to Cloudflare Pages. The project uses Pages Functions for the API and Cloudflare KV for persistence, so there is no separate database to manage.
Prerequisites
- A Cloudflare account
- A JavaScript runtime, such as Bun or Node.js
The examples below use Bun because that is what I use personally. If you are only adapting the deployment flow, you can replace the package-manager commands with npm, pnpm, or yarn equivalents.
If Wrangler is not authenticated yet, run bunx wrangler login before you create the KV namespace or deploy the site.
Deploy to Cloudflare Pages
- Clone the repository and install dependencies:
git clone https://github.com/xueelf/tally-api.git
cd tally-api
bun install- Create a KV namespace:
bunx wrangler kv namespace create KV- Copy the returned
idintokv_namespacesinwrangler.json:
"kv_namespaces": [{ "binding": "KV", "id": "<your KV id>" }]Replace the placeholder with the real namespace ID. Without it, local development and deployment will fail.
- Generate worker type definitions:
bun run types- Build the docs site:
bun run docs:build- Deploy to Cloudflare Pages:
bunx wrangler pages deployWrangler uses the pages_build_output_dir setting from wrangler.json, so the static docs and the API routes under functions are deployed together.
Local Development
bun run devThis script builds the docs, generates types, and starts wrangler pages dev ./dist. Once it is running, open http://localhost:8788 to test the docs site and API locally.
Notes
If all you want is your own counter service, the steps above are enough. After that, you can switch the domain, adjust the copy, or pick a different theme if needed.
For route rules, response formats, and error handling, see API Reference.