mirror of
https://github.com/tiennm99/rplace.git
synced 2026-10-11 03:13:48 +00:00
* refactor(rate-limit): switch to 1 req/sec cooldown, batch size up to 2048
Replace per-pixel credit/token-bucket model with a simple per-user cooldown
(SET NX EX 1). Batch size is now independent of the rate limit and capped
at MAX_BATCH_SIZE = 2048.
- rate-limiter: SET NX EX replaces Lua credit script
- worker: response shape { ok: true } (no credits field)
- client: drop credit state/timer/UserInfo; uploader paces by cooldown
- tests: mock checkRateLimit; integration test exercises SET NX EX
- docs: README, system-architecture, code-standards, deployment-guide
* chore(plans): remove implemented plan directories
rplace-implementation (base build), review-fixes, and
image-importer-enhancements are all shipped. Keep plans/reports/ as
historical code-review and research references.
2.2 KiB
2.2 KiB
Deployment Guide
Prerequisites
- Node.js 18+
- Cloudflare account (free tier)
- Upstash Redis database (free tier)
wranglerCLI (installed as dev dependency)
Step 1: Create Upstash Redis Database
- Go to console.upstash.com
- Create a new Redis database
- Choose a region close to your users
- Copy the REST URL and REST Token
Step 2: Configure Secrets
# Set secrets in Cloudflare (not in code)
npx wrangler secret put UPSTASH_REDIS_REST_URL
npx wrangler secret put UPSTASH_REDIS_REST_TOKEN
For local development, create .dev.vars:
UPSTASH_REDIS_REST_URL=https://your-url.upstash.io
UPSTASH_REDIS_REST_TOKEN=your-token
Step 3: Deploy
npm run deploy
This runs vite build (compiles Svelte → dist/) then wrangler deploy (uploads Worker + static assets).
Step 4: Verify
- Visit your Worker URL (e.g.,
https://rplace.your-subdomain.workers.dev) - Canvas should load (empty/dark on first visit)
- Select a color, click to place a pixel
- Open a second browser tab — pixel should appear via WebSocket
Custom Domain
# Add a custom domain via Cloudflare dashboard or:
npx wrangler domains add rplace.yourdomain.com
Monitoring
- Cloudflare dashboard: Worker analytics, request logs, DO metrics
- Upstash console: Redis command count, memory usage, latency
Cost Estimates (Free Tier)
| Resource | Free Limit | rplace Usage |
|---|---|---|
| CF Workers | 100K requests/day | Canvas reads + pixel placements |
| CF Durable Objects | Free with Workers | WebSocket connections |
| Upstash Redis | 10K commands/day | BITFIELD reads/writes + cooldown SET NX EX |
For hobby traffic (< few hundred users/day), free tiers are sufficient. Upstash pay-as-you-go ($0.2/100K commands) is the first thing to hit limits.
Troubleshooting
- Canvas loads empty: Check Upstash credentials in secrets
- Pixels don't persist: Verify BITFIELD support — test with
redis-cli BITFIELD canvas SET u5 #0 1 - WebSocket not connecting: Ensure Durable Object migration ran (check
wrangler.jsonmigrations) - Rate limiting not working: Verify
SET key value NX EX 1returns"OK"/nullas expected on your Upstash tier