37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Simple HTTP server to serve the UI files
|
|
"""
|
|
import http.server
|
|
import socketserver
|
|
import os
|
|
import webbrowser
|
|
from pathlib import Path
|
|
|
|
# Change to the ui directory
|
|
ui_dir = Path(__file__).parent / "ui"
|
|
os.chdir(ui_dir)
|
|
|
|
PORT = 3000
|
|
|
|
class MyHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
|
|
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()
|
|
|
|
if __name__ == "__main__":
|
|
with socketserver.TCPServer(("", PORT), MyHTTPRequestHandler) as httpd:
|
|
print(f"🌐 Serving UI at http://localhost:{PORT}")
|
|
print(f"📁 Serving files from: {ui_dir.absolute()}")
|
|
print("💡 Make sure the API server is running on http://localhost:8000")
|
|
print("🔄 Press Ctrl+C to stop")
|
|
|
|
# Try to open browser
|
|
try:
|
|
webbrowser.open(f"http://localhost:{PORT}")
|
|
except:
|
|
pass
|
|
|
|
httpd.serve_forever() |