66 lines
1.6 KiB
Python
Executable File
66 lines
1.6 KiB
Python
Executable File
#!/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()
|
|
|