-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
51 lines (44 loc) Β· 1.66 KB
/
server.py
File metadata and controls
51 lines (44 loc) Β· 1.66 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
#!/usr/bin/env python3
"""
Simple HTTP server for local testing of the portfolio website
"""
import http.server
import socketserver
import os
import sys
from pathlib import Path
# Change to the directory containing the static files
os.chdir(Path(__file__).parent)
PORT = 8000
class CustomHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
def end_headers(self):
# Add CORS headers for local development
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 do_GET(self):
# Serve index.html for all routes (SPA behavior)
if self.path == '/':
self.path = '/index.html'
elif not os.path.exists(self.path[1:]) and not self.path.startswith('/static'):
self.path = '/index.html'
return super().do_GET()
def run_server():
"""Start the local development server"""
try:
with socketserver.TCPServer(("", PORT), CustomHTTPRequestHandler) as httpd:
print(f"π Portfolio server running at http://localhost:{PORT}")
print(f"π Serving files from: {os.getcwd()}")
print("π₯ Next-gen AI Security Portfolio is live!")
print("π‘ Press Ctrl+C to stop the server")
print("-" * 50)
httpd.serve_forever()
except KeyboardInterrupt:
print("\nπ Server stopped by user")
sys.exit(0)
except Exception as e:
print(f"β Error starting server: {e}")
sys.exit(1)
if __name__ == "__main__":
run_server()