-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.py
More file actions
36 lines (30 loc) · 1.16 KB
/
server.py
File metadata and controls
36 lines (30 loc) · 1.16 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
#!/usr/bin/env python3
"""
Simple HTTP server to serve the Legal Boolean Search Builder HTML application.
Serves on 0.0.0.0:5000 to work with Replit's environment.
"""
import http.server
import socketserver
import os
from http.server import SimpleHTTPRequestHandler
class CustomHandler(SimpleHTTPRequestHandler):
def end_headers(self):
# Add cache control headers to prevent caching issues in Replit's iframe
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()
def do_GET(self):
# Serve index.html for root path
if self.path == '/':
self.path = '/index.html'
return super().do_GET()
if __name__ == "__main__":
PORT = 5000
HOST = "0.0.0.0"
# Change to the directory containing our files
os.chdir(os.path.dirname(os.path.abspath(__file__)))
with socketserver.TCPServer((HOST, PORT), CustomHandler) as httpd:
print(f"Server running at http://{HOST}:{PORT}/")
print("Serving Legal Boolean Search Builder...")
httpd.serve_forever()