#!/usr/bin/env bash # Start RustyCMS API + Admin UI and open browser set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR" # Cleanup on exit cleanup() { echo "Shutting down..." kill 0 2>/dev/null || true } trap cleanup EXIT INT TERM # Start API in background echo "Starting RustyCMS API on http://127.0.0.1:3000 ..." cargo run & API_PID=$! # Wait for API to be ready echo "Waiting for API..." for i in {1..30}; do if curl -s http://127.0.0.1:3000/health >/dev/null 2>&1; then echo "API is ready." break fi sleep 0.5 if ! kill -0 $API_PID 2>/dev/null; then echo "API failed to start." >&2 exit 1 fi done # Ensure admin-ui dependencies are up to date echo "Installing Admin UI dependencies..." (cd admin-ui && npm install) # Start Admin UI in background echo "Starting Admin UI on http://localhost:2001 ..." (cd admin-ui && npm run dev) & UI_PID=$! # Wait for Admin UI to be ready echo "Waiting for Admin UI..." for i in {1..30}; do if curl -s http://localhost:2001 >/dev/null 2>&1; then echo "Admin UI is ready." break fi sleep 0.5 if ! kill -0 $UI_PID 2>/dev/null; then echo "Admin UI failed to start." >&2 exit 1 fi done # Open browser if command -v open >/dev/null 2>&1; then open http://localhost:2001 elif command -v xdg-open >/dev/null 2>&1; then xdg-open http://localhost:2001 else echo "Open http://localhost:2001 in your browser." fi echo "" echo "RustyCMS running:" echo " API: http://127.0.0.1:3000" echo " Admin UI: http://localhost:2001" echo "" echo "Press Ctrl+C to stop both." wait