#!/bin/bash set -e # Colors GREEN='\033[0;32m' YELLOW='\033[1;33m' RED='\033[0;31m' NC='\033[0m' echo -e "${GREEN}🚀 Website Monitoring — Local Development Setup${NC}" echo "================================================" echo "" # 1. Check prerequisites echo -e "${YELLOW}[1/6] Checking prerequisites...${NC}" command -v node >/dev/null 2>&1 || { echo -e "${RED}❌ Node.js not found. Install it from https://nodejs.org${NC}"; exit 1; } command -v docker >/dev/null 2>&1 || { echo -e "${RED}❌ Docker not found. Install Docker Desktop.${NC}"; exit 1; } command -v supabase >/dev/null 2>&1 || { echo -e "${RED}❌ Supabase CLI not found. Run: brew install supabase/tap/supabase${NC}"; exit 1; } echo " ✅ Node $(node --version), Docker, Supabase CLI found" # 2. Start Supabase (if not already running) echo "" echo -e "${YELLOW}[2/6] Starting local Supabase...${NC}" cd website-monitoring-frontend if supabase status 2>&1 | grep -q "API URL"; then echo " ✅ Supabase already running" else echo " ⏳ Starting Supabase (first time takes ~5 min to pull images)..." supabase start fi # Extract keys from supabase status API_URL=$(supabase status 2>&1 | grep "API URL" | awk '{print $NF}') ANON_KEY=$(supabase status 2>&1 | grep "anon key" | awk '{print $NF}') SERVICE_KEY=$(supabase status 2>&1 | grep "service_role key" | awk '{print $NF}') STUDIO_URL=$(supabase status 2>&1 | grep "Studio URL" | awk '{print $NF}') echo " ✅ Supabase running:" echo " API: $API_URL" echo " Studio: $STUDIO_URL" # 3. Create frontend .env.local echo "" echo -e "${YELLOW}[3/6] Configuring frontend environment...${NC}" cat > .env.local << EOF # Auto-generated by dev-setup.sh — local Supabase NEXT_PUBLIC_SUPABASE_URL=${API_URL} NEXT_PUBLIC_SUPABASE_ANON_KEY=${ANON_KEY} SUPABASE_SERVICE_ROLE_KEY=${SERVICE_KEY} LIGHTHOUSE_SERVICE_URL=http://localhost:5000 CRON_SECRET=local-dev-secret EOF echo " ✅ Created website-monitoring-frontend/.env.local" cd .. # 4. Create backend .env echo "" echo -e "${YELLOW}[4/6] Configuring backend environment...${NC}" cat > website-monitoring-backend/.env << EOF PORT=5000 CORS_ORIGIN=http://localhost:3000 NODE_ENV=development EOF echo " ✅ Created website-monitoring-backend/.env" # 5. Install dependencies echo "" echo -e "${YELLOW}[5/6] Installing dependencies...${NC}" npm install --silent 2>/dev/null cd website-monitoring-backend && npm install --silent 2>/dev/null && cd .. cd website-monitoring-frontend && npm install --silent 2>/dev/null && cd .. echo " ✅ Dependencies installed" # 6. Run database migrations echo "" echo -e "${YELLOW}[6/6] Applying database migrations...${NC}" cd website-monitoring-frontend supabase db reset --no-seed 2>/dev/null || echo " ⚠️ Migrations may need manual review (run: cd website-monitoring-frontend && supabase db reset)" cd .. echo "" echo -e "${GREEN}════════════════════════════════════════════${NC}" echo -e "${GREEN}✅ Setup complete! Start developing:${NC}" echo "" echo " npm run dev" echo "" echo -e " Frontend: ${GREEN}http://localhost:3000${NC}" echo -e " Backend: ${GREEN}http://localhost:5000${NC}" echo -e " Supabase: ${GREEN}${STUDIO_URL}${NC} (admin DB browser)" echo "" echo -e "${YELLOW}📋 Quick commands:${NC}" echo " npm test — run all tests" echo " npm run build — build everything" echo " npm run lint — lint everything" echo " supabase stop — stop local DB (in website-monitoring-frontend/)" echo "" echo -e "${YELLOW}🔑 Test cron endpoints locally:${NC}" echo " curl -H 'Authorization: Bearer local-dev-secret' http://localhost:3000/api/cron/uptime" echo ""