-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_server.py
More file actions
38 lines (33 loc) · 1.33 KB
/
Copy pathsimple_server.py
File metadata and controls
38 lines (33 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python3
"""
Simple HTTP server with CORS support for WebLLM
"""
import http.server
import socketserver
from http.server import SimpleHTTPRequestHandler
class CORSRequestHandler(SimpleHTTPRequestHandler):
def end_headers(self):
# Add CORS headers
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
self.send_header('Access-Control-Allow-Headers', '*')
self.send_header('Cross-Origin-Embedder-Policy', 'require-corp')
self.send_header('Cross-Origin-Opener-Policy', 'same-origin')
super().end_headers()
def do_OPTIONS(self):
self.send_response(200)
self.end_headers()
PORT = 8000
with socketserver.TCPServer(("", PORT), CORSRequestHandler) as httpd:
print(f"✅ Server running at http://localhost:{PORT}/")
print(f"📁 Serving directory: {httpd.server_address}")
print(f"🌐 CORS enabled for WebLLM")
print(f"🔒 Cross-Origin headers set")
print("\n📋 Access your app:")
print(f" Frontend: http://localhost:{PORT}/frontend/")
print(f" AI Chat: http://localhost:{PORT}/frontend/ai-chat.html")
print("\nPress Ctrl+C to stop the server")
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("\n\n🛑 Server stopped")