-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
27 lines (23 loc) · 967 Bytes
/
Copy pathserver.py
File metadata and controls
27 lines (23 loc) · 967 Bytes
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
import http.server
import socketserver
import os
class CORSHandler(http.server.SimpleHTTPRequestHandler):
def end_headers(self):
self.send_header('Cross-Origin-Opener-Policy', 'same-origin')
self.send_header('Cross-Origin-Embedder-Policy', 'require-corp')
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Cache-Control', 'no-cache')
super().end_headers()
def guess_type(self, path):
if path.endswith(".mjs") or path.endswith(".js"):
return "text/javascript"
if path.endswith(".wasm"):
return "application/wasm"
return super().guess_type(path)
PORT = 8000
class ThreadingTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
allow_reuse_address = True
with ThreadingTCPServer(("", PORT), CORSHandler) as httpd:
print(f"Server active on port {PORT}")
print(f"Root directory: {os.getcwd()}")
httpd.serve_forever()