|
|
|
|
|
""" |
|
|
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): |
|
|
|
|
|
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() |
|
|
|