-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.py
More file actions
40 lines (32 loc) · 1.4 KB
/
server.py
File metadata and controls
40 lines (32 loc) · 1.4 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
import http.server
import socketserver
import os
# Port to listen on
PORT = 8000
class VJServerHandler(http.server.SimpleHTTPRequestHandler):
def end_headers(self):
"""
Add the headers required to enable SharedArrayBuffer (COOP/COEP).
These allow the browser to isolate the execution environment safely.
"""
self.send_header('Cross-Origin-Embedder-Policy', 'require-corp')
self.send_header('Cross-Origin-Opener-Policy', 'same-origin')
# Also helpful for development/testing
self.send_header('Cache-Control', 'no-store, no-cache, must-revalidate')
super().end_headers()
def run_server():
# Ensure we are serving from the directory where the script is located
# os.chdir(os.path.dirname(os.path.abspath(__file__)))
with socketserver.TCPServer(("", PORT), VJServerHandler) as httpd:
print(f"--- VJ LIVE TERMINAL SERVER ---")
print(f"Location: http://localhost:{PORT}")
print(f"Status: COOP/COEP Headers Active (SharedArrayBuffer Enabled)")
print(f"Action: Open index.html in your browser via this URL.")
print(f"Press CTRL+C to stop.")
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("\nShutting down server.")
httpd.server_close()
if __name__ == "__main__":
run_server()