serve.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/bash
  2. # Simple HTTP server for viewing the dashboard
  3. # Auto-opens browser and shuts down after timeout
  4. # Usage: ./serve.sh [port] [timeout_seconds]
  5. PORT=${1:-8000}
  6. TIMEOUT=${2:-15}
  7. cd "$(dirname "$0")" || exit
  8. echo "🚀 Starting HTTP server on port $PORT..."
  9. echo "📊 Opening dashboard in browser..."
  10. echo "⏱️ Server will auto-shutdown in ${TIMEOUT} seconds"
  11. echo ""
  12. # Start server in background
  13. python3 -m http.server $PORT > /dev/null 2>&1 &
  14. SERVER_PID=$!
  15. # Wait for server to start
  16. sleep 1
  17. # Open browser
  18. if command -v open > /dev/null; then
  19. # macOS
  20. open "http://localhost:$PORT"
  21. elif command -v xdg-open > /dev/null; then
  22. # Linux
  23. xdg-open "http://localhost:$PORT"
  24. elif command -v start > /dev/null; then
  25. # Windows
  26. start "http://localhost:$PORT"
  27. else
  28. echo "⚠️ Could not auto-open browser. Please visit: http://localhost:$PORT"
  29. fi
  30. echo "✅ Dashboard opened in browser"
  31. echo "⏳ Waiting ${TIMEOUT} seconds for page to load..."
  32. # Countdown
  33. for i in $(seq $TIMEOUT -1 1); do
  34. printf "\r⏱️ Shutting down in %2d seconds... (Press Ctrl+C to keep running)" $i
  35. sleep 1
  36. done
  37. echo ""
  38. echo "🛑 Stopping server..."
  39. kill $SERVER_PID 2>/dev/null
  40. echo "✅ Server stopped. Dashboard data is cached in your browser."