-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev_server.py
More file actions
33 lines (28 loc) · 1 KB
/
dev_server.py
File metadata and controls
33 lines (28 loc) · 1 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
import http.server
import socketserver
import webbrowser
import threading
PORT = 8000
def open_browser():
import time
time.sleep(1) # Počkat, než se server spustí
webbrowser.open(f'http://localhost:{PORT}')
# Spustit otevření prohlížeče v novém vlákně
browser_thread = threading.Thread(target=open_browser, daemon=True)
browser_thread.start()
# Vlastní handler bez cache
class NoCacheHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
def end_headers(self):
self.send_header('Cache-Control', 'no-cache, no-store, must-revalidate')
self.send_header('Pragma', 'no-cache')
self.send_header('Expires', '0')
super().end_headers()
# Spustit server v hlavním vlákně
Handler = NoCacheHTTPRequestHandler
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print(f"Serving at http://localhost:{PORT}")
print("Press Ctrl+C to stop the server")
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("Server stopped")