cduss's picture
wip
bee5688
#!/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()