Pular para o conteúdo

Local Development

Unified Dev Environment

The easiest way to run everything is through the unified dev proxy:

Terminal window
# Start all services (site on :3000, workers on :8787–8790)
node scripts/dev.js
# With a fresh site build first
node scripts/dev.js --build
# Stop all services
node scripts/dev-stop.js

Access Points

ServiceURL
Static Sitehttp://localhost:3000
API (via proxy)http://localhost:3000/api/…
Chat Workerhttp://localhost:8787
Auth Workerhttp://localhost:8788
Billing Workerhttp://localhost:8789
Listings Workerhttp://localhost:8790

Proxy Routing

The dev proxy routes /api/* based on path prefix:

PrefixTarget Worker
/api/auth/*auth-worker (8788)
/api/billing/*billing-worker (8789)
/api/listings*listings-worker (8790)
All other /api/*chat-worker (8787)

Individual Worker Development

You can also run workers independently:

Terminal window
# Auth worker
cd auth-worker && npm run dev
# Billing worker
cd billing-worker && npm run dev
# Listings worker
cd listings-worker && npm run dev
# Chat worker
cd chat-worker
npx wrangler d1 migrations apply redecasas-chat --local
npm run dev

Site Generator Development

The site generator is a Go CLI with many commands:

Terminal window
cd site
# Full rebuild
go run . build-pages
# Build only static assets (JS/CSS/images)
go run . build-static
# Build a single page
go run . build-page home
go run . build-page scope:energia-solar
go run . build-page topic:iptu
# Run rotating daily update
go run . daily-update --force
# Generate sitemap
go run . generate-sitemap
# Start a local file server
go run . server

Database (Local SQLite)

Terminal window
cd db
# Create database and run migrations
sqlite3 redecasas.db < schema.sql
# Build and run seeder
cd seeder
go build -o seeder .
./seeder --db-url="../redecasas.db" --site-dir="../site" --csv-file="../Table.csv"
# Run post-seed resolution
sqlite3 redecasas.db < post_seed.sql

Troubleshooting

Port already in use

Terminal window
# Find what's using port 3000
lsof -i :3000
# Kill it or change the port in scripts/dev.js

Chat worker D1 errors

Make sure you apply migrations first:

Terminal window
cd chat-worker
npx wrangler d1 migrations apply redecasas-chat --local

Missing pages

If you see 404s for city or state pages, run a full build:

Terminal window
cd site && go run . build-pages