-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserve.py
More file actions
executable file
·52 lines (42 loc) · 1.45 KB
/
serve.py
File metadata and controls
executable file
·52 lines (42 loc) · 1.45 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
"""
Simple HTTP server for Emotion Net project
Serves the project locally on http://localhost:8080
"""
import http.server
import socketserver
import os
import webbrowser
import sys
from pathlib import Path
PORT = 8080
PROJECT_DIR = Path(__file__).parent
class MyHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
def log_message(self, format, *args):
print(f"[{self.log_date_time_string()}] {format % args}")
def end_headers(self):
# Add headers to prevent caching during development
self.send_header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')
super().end_headers()
def run_server():
os.chdir(PROJECT_DIR)
handler = MyHTTPRequestHandler
with socketserver.TCPServer(("", PORT), handler) as httpd:
print(f"🚀 Emotion Net Server")
print(f"=" * 50)
print(f"📍 Serving files from: {PROJECT_DIR}")
print(f"🌐 Open your browser at: http://localhost:{PORT}")
print(f"=" * 50)
print(f"\n✨ Press Ctrl+C to stop the server\n")
try:
# Open browser automatically
webbrowser.open(f'http://localhost:{PORT}')
except Exception as e:
print(f"⚠️ Could not open browser: {e}")
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("\n\n👋 Server stopped")
sys.exit(0)
if __name__ == "__main__":
run_server()