Cloudflare Worker for the 1mb community counter.
| Method | Path | Description |
|---|---|---|
| GET | / |
Returns { count: number } |
| POST | / |
Increment count (1 per IP per 24h) |
| GET | /health |
Service health status |
npx wrangler loginnpx wrangler secret put UPSTASH_REDIS_REST_URL --config workers/wrangler.toml
npx wrangler secret put UPSTASH_REDIS_REST_TOKEN --config workers/wrangler.tomlnpm run worker:deploynpm run worker:dev # local development server
npm run worker:deploy # deploy to production
npm run worker:tail # view live logsnpm test # run test suite
npm run test:watch # run in watch modeTests use @cloudflare/vitest-pool-workers to run the worker in a local Cloudflare runtime with mocked Redis (via fetchMock).
Worker deployment is automated via GitHub Actions (.github/workflows/deploy-worker.yml). Pushes to main that modify workers/** trigger:
- Test — runs
npm test - Deploy — deploys via
wrangler-action@v3
Setup: Add CLOUDFLARE_API_TOKEN as a repo secret. Create the token at the Cloudflare dashboard with "Workers Scripts: Edit" permission.
- URL: https://1mb-counter.vmx-builds.workers.dev
- Health: https://1mb-counter.vmx-builds.workers.dev/health
Client (1mb.dev)
↓
Cloudflare Worker (counter.js)
↓
Upstash Redis (managed)
- Rate limiting: 1 vote per IP per 24h (IP is hashed, not stored)
- Offline fallback: Client shows "—" if API unavailable