#!/usr/bin/env bash set -e RELAY_PORT=7777 RELAY_URL="ws://localhost:$RELAY_PORT" VITE_PORT=5174 cleanup() { echo "" echo "Shutting down..." # Kill background jobs (relay) kill $(jobs -p) 2>/dev/null exit 0 } trap cleanup SIGINT SIGTERM # Check that nak is installed if ! command -v nak &>/dev/null; then echo "Error: 'nak' is not installed." echo "Install with: brew install nak" exit 1 fi # Kill any existing process on the relay port if lsof -i :$RELAY_PORT -P &>/dev/null; then echo "Port $RELAY_PORT is already in use, killing existing process..." lsof -ti :$RELAY_PORT | xargs kill -9 2>/dev/null sleep 1 fi # Start the local relay in the background echo "Starting local Nostr relay on port $RELAY_PORT..." nak serve --port $RELAY_PORT & RELAY_PID=$! # Wait for the relay to be ready echo "Waiting for relay to be ready..." for i in $(seq 1 30); do if curl -s -o /dev/null http://localhost:$RELAY_PORT 2>/dev/null; then echo "Relay is ready at $RELAY_URL (pid $RELAY_PID)" break fi if ! kill -0 $RELAY_PID 2>/dev/null; then echo "Error: relay process died unexpectedly" exit 1 fi sleep 0.5 done # Verify relay is actually responding if ! curl -s -o /dev/null http://localhost:$RELAY_PORT 2>/dev/null; then echo "Error: relay did not start in time" kill $RELAY_PID 2>/dev/null exit 1 fi # Seed test profiles and activity echo "" echo "Seeding test profiles..." npx tsx scripts/seed-profiles.ts echo "" echo "Seeding activity (reactions & comments)..." npx tsx scripts/seed-activity.ts echo "" # Start the Vite dev server (in foreground so Ctrl+C works) echo "Starting dev server..." echo "============================================" echo " Relay: $RELAY_URL (pid $RELAY_PID)" echo " App: http://localhost:$VITE_PORT" echo " Press Ctrl+C to stop everything" echo "============================================" echo "" npx vite --port $VITE_PORT