-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart_server.py
More file actions
executable file
·88 lines (73 loc) · 2.74 KB
/
Copy pathstart_server.py
File metadata and controls
executable file
·88 lines (73 loc) · 2.74 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python3
"""
Simple web server for the Historical Universe Models application.
This script starts a local HTTP server to serve the 3D visualization app.
"""
import http.server
import socketserver
import webbrowser
import os
import sys
from pathlib import Path
def main():
"""Start the web server and open the application in a browser."""
# Configuration
PORT = 8000
HOST = 'localhost'
# Ensure we're in the correct directory
script_dir = Path(__file__).parent
os.chdir(script_dir)
# Check if required files exist
required_files = ['index.html', 'js/app.js']
missing_files = []
for file_path in required_files:
if not Path(file_path).exists():
missing_files.append(file_path)
if missing_files:
print("❌ Error: Missing required files:")
for file_path in missing_files:
print(f" - {file_path}")
print("\nPlease ensure all application files are present.")
sys.exit(1)
# Create server
try:
handler = http.server.SimpleHTTPRequestHandler
httpd = socketserver.TCPServer((HOST, PORT), handler)
print(f"🌌 Historical Universe Models - 3D Explorer")
print(f"{'='*50}")
print(f"🚀 Server starting on http://{HOST}:{PORT}")
print(f"📂 Serving from: {script_dir}")
print(f"{'='*50}")
print(f"")
print(f"🎯 Main Application: http://{HOST}:{PORT}/")
print(f"📋 Demo Page: http://{HOST}:{PORT}/demo.html")
print(f"")
print(f"💡 The application will open automatically in your browser.")
print(f" If it doesn't, copy and paste the URL above.")
print(f"")
print(f"⏹️ Press Ctrl+C to stop the server")
print(f"{'='*50}")
# Try to open the application in the default browser
try:
webbrowser.open(f"http://{HOST}:{PORT}/demo.html")
except Exception as e:
print(f"⚠️ Could not auto-open browser: {e}")
print(f" Please manually open http://{HOST}:{PORT}/ in your browser")
# Start the server
httpd.serve_forever()
except KeyboardInterrupt:
print(f"\n🛑 Server stopped by user")
httpd.shutdown()
sys.exit(0)
except OSError as e:
if e.errno == 48: # Address already in use
print(f"❌ Error: Port {PORT} is already in use.")
print(f" Try using a different port or stop the other server.")
else:
print(f"❌ Error starting server: {e}")
sys.exit(1)
except Exception as e:
print(f"❌ Unexpected error: {e}")
sys.exit(1)
if __name__ == "__main__":
main()