#!/usr/bin/env python3 """ Simple HTTP server to serve the static Reachy Mini Control Panel. This is only needed if you want to serve the files, otherwise you can open index.html directly. """ import http.server import socketserver import os from pathlib import Path PORT = 7860 DIRECTORY = Path(__file__).parent class MyHTTPRequestHandler(http.server.SimpleHTTPRequestHandler): def __init__(self, *args, **kwargs): super().__init__(*args, directory=str(DIRECTORY), **kwargs) def end_headers(self): # Add CORS headers to allow localhost:8000 WebSocket connections self.send_header('Access-Control-Allow-Origin', '*') self.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS') self.send_header('Access-Control-Allow-Headers', 'Content-Type') super().end_headers() def main(): os.chdir(DIRECTORY) with socketserver.TCPServer(("", PORT), MyHTTPRequestHandler) as httpd: print(f"šŸ¤– Reachy Mini Control Panel") print(f"šŸ“” Serving at http://localhost:{PORT}") print(f"šŸ“ Directory: {DIRECTORY}") print(f"\nšŸ”— Open http://localhost:{PORT} in your browser") print(f"āš ļø Make sure robot daemon is running on localhost:8000") print(f"\nPress Ctrl+C to stop\n") try: httpd.serve_forever() except KeyboardInterrupt: print("\n\nšŸ‘‹ Shutting down server...") if __name__ == "__main__": main()