forked from joinpursuit/FSW-Personal-Website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-server.py
More file actions
41 lines (34 loc) · 1.41 KB
/
dev-server.py
File metadata and controls
41 lines (34 loc) · 1.41 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
#!/usr/bin/env python3
"""
Simple HTTP server with no-cache headers for development.
This prevents browser caching issues when updating images/CSS/JS.
"""
import http.server
import socketserver
from datetime import datetime
PORT = 8080
class NoCacheHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
def end_headers(self):
# Add no-cache headers to prevent browser caching during development
self.send_header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')
self.send_header('Pragma', 'no-cache')
self.send_header('Expires', '0')
super().end_headers()
def log_message(self, format, *args):
# Add timestamp to log messages
sys.stderr.write("%s - - [%s] %s\n" %
(self.address_string(),
self.log_date_time_string(),
format % args))
if __name__ == '__main__':
import sys
with socketserver.TCPServer(("", PORT), NoCacheHTTPRequestHandler) as httpd:
print(f"🚀 Dev server running at http://localhost:{PORT}")
print(f"📁 Serving from: {httpd.server_address}")
print(f"⚡ No-cache headers enabled - images/CSS will always reload fresh")
print(f"Press Ctrl+C to stop\n")
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("\n\n✅ Server stopped")
sys.exit(0)