-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathserver.py
More file actions
37 lines (31 loc) · 1.09 KB
/
server.py
File metadata and controls
37 lines (31 loc) · 1.09 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
#!/usr/bin/env python3
"""
Simple HTTP server with WASM MIME type support
"""
import http.server
import socketserver
import mimetypes
import sys
import os
# Add WASM MIME type
mimetypes.add_type('application/wasm', '.wasm')
class WASMHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
def end_headers(self):
# Add CORS headers for local development
self.send_header('Cross-Origin-Embedder-Policy', 'require-corp')
self.send_header('Cross-Origin-Opener-Policy', 'same-origin')
super().end_headers()
def main():
port = int(sys.argv[1]) if len(sys.argv) > 1 else 8888
# Change to web directory to serve it as root
if os.path.exists('web'):
os.chdir('web')
print("Serving web/ directory as root")
else:
print("Warning: web/ directory not found, serving current directory")
with socketserver.TCPServer(("", port), WASMHTTPRequestHandler) as httpd:
print(f"Serving at http://localhost:{port}")
print("WASM MIME type support enabled")
httpd.serve_forever()
if __name__ == '__main__':
main()