-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
49 lines (41 loc) · 1.56 KB
/
server.py
File metadata and controls
49 lines (41 loc) · 1.56 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
#!/usr/bin/env python3
"""
Simple HTTP server for the SpaceX Landing Prediction Dashboard
"""
import http.server
import socketserver
import webbrowser
import os
from pathlib import Path
class CORSHTTPRequestHandler(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()
def main():
# Set the port
PORT = 8000
# Change to the directory containing the files
os.chdir(Path(__file__).parent)
# Create the server
with socketserver.TCPServer(("", PORT), CORSHTTPRequestHandler) as httpd:
print(f"🚀 SpaceX Dashboard Server Starting...")
print(f"📊 Dashboard available at: http://localhost:{PORT}")
print(f"📁 Serving files from: {os.getcwd()}")
print(f"🛑 Press Ctrl+C to stop the server")
print("-" * 50)
# Open the dashboard in the default browser
try:
webbrowser.open(f'http://localhost:{PORT}')
print("🌐 Opening dashboard in your default browser...")
except:
print("⚠️ Could not open browser automatically. Please navigate to http://localhost:8000")
# Start the server
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("\n🛑 Server stopped by user")
httpd.shutdown()
if __name__ == "__main__":
main()