npm run build and wrangler deploy must be run from the user's Windows terminal. The sandbox/AI environment cannot run esbuild Windows binaries or authenticate with Cloudflare (gets 403).Overview
The portal has two deployable pieces:
- Cloudflare Pages — serves the React frontend. Auto-deploys when
mainis pushed to GitHub. - Cloudflare Worker — serves the API (
buildright-api.sonandigital.com). Deployed manually with Wrangler.
Frontend Deploy (Cloudflare Pages)
- Build the frontend:
cd E:\Claude_Projects\sonan-trackers\contractor-portal npm run build - Push the commit to GitHub main (from Windows terminal):
git push origin <commit_sha>:refs/heads/main - Cloudflare Pages automatically picks up the push and deploys the
dist/folder. - Live at: buildright.sonandigital.com
Worker Deploy (API)
- Ensure
wrangler.tomlis correct (D1 binding, worker namebuildright) - Deploy the worker from Windows terminal:
cd E:\Claude_Projects\sonan-trackers\contractor-portal npx wrangler deploy - Live at: buildright-api.sonandigital.com
GitHub Push (FUSE-Safe Pattern)
Because the repo lives on a FUSE mount, .git/config is always corrupted after an AI session. Before pushing, run all of these from the Windows terminal:
del .git\config.lock
echo [core] > .git\config
echo repositoryformatversion = 0 >> .git\config
echo filemode = false >> .git\config
echo bare = false >> .git\config
git remote add origin https://github.com/sonantechai/contractor-portal.git
git push origin <commit_sha>:refs/heads/main
Current latest pushed SHA: ec6702c81726efb2c967be56c8267b281dd4ba13
Database Migrations
Migrations live in migrations/ at the repo root.
| Migration | Contents | Status |
|---|---|---|
0001_init.sql | All tables: settings, clients, service_requests, jobs, estimates, invoices, appointments, employees | Applied to remote D1 |
0006_recurring_appointments.sql | Adds recurring, recurrence, recurring_end_date columns to appointments | Applied to remote D1 |
0007_recurring_days.sql | Adds recurring_days (JSON array of day indices) column to appointments | Applied to remote D1 |
employees table was created as part of the initial 0001_init.sql migration — it was always part of the schema. No separate migration is needed for the employee / Team feature.Migrations 0001 through any subsequent ones are already applied to the remote D1 database (contractor_db, UUID: 5f5efd19-3979-4c1b-a75c-ebd9e2256736).
Running a new migration
If a new migration is needed in future:
npx wrangler d1 execute contractor_db --remote --file=migrations/0002_new_migration.sql
Environment / Secrets
No environment variables are required for the Worker beyond what is in wrangler.toml (D1 binding). Auth secrets (PBKDF2 salt, JWT secret) are hardcoded defaults in the worker — they can be moved to Wrangler secrets if needed:
npx wrangler secret put JWT_SECRET
Local Development
# Frontend dev server
npm run dev
# Worker local (with D1 local emulation)
npx wrangler dev worker/index.ts --local --persist
Local D1 is separate from remote D1. Changes to local are not reflected in production.