#!/usr/bin/env python3 """ Web Adventure - Community RPG Launcher Simple script to start both backend and frontend """ import subprocess import time import sys import os import signal import webbrowser from pathlib import Path def main(): print("\n" + "="*60) print("šŸŽ® WEB ADVENTURE - Community RPG") print("="*60 + "\n") # Get the directory of this script script_dir = Path(__file__).parent.resolve() os.chdir(script_dir) # Start the backend print("šŸš€ Starting backend server...") backend_process = subprocess.Popen( [sys.executable, "-m", "uvicorn", "backend:app", "--host", "0.0.0.0", "--port", "8000"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, preexec_fn=os.setsid ) # Wait for backend to start time.sleep(2) if backend_process.poll() is not None: print("āŒ Backend failed to start!") sys.exit(1) print("āœ… Backend running at http://localhost:8000") print("\n" + "="*60) print("šŸŒ Opening game in browser...") print("="*60 + "\n") # Open the frontend in the browser html_path = (script_dir / "index.html").as_uri() webbrowser.open(html_path) print(f"\nšŸ“– API Documentation: http://localhost:8000/docs") print(f"šŸŽ® Game: {html_path}\n") print("Press Ctrl+C to stop the server\n") try: backend_process.wait() except KeyboardInterrupt: print("\n\nShutting down...") os.killpg(os.getpgid(backend_process.pid), signal.SIGTERM) backend_process.wait() print("āœ… Server stopped") if __name__ == "__main__": main()