-
Notifications
You must be signed in to change notification settings - Fork 1
/
servewasm.py
executable file
·37 lines (26 loc) · 1.12 KB
/
servewasm.py
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 python
import mimetypes
mimetypes.init()
if ".wasm" not in mimetypes.types_map:
mimetypes.add_type("application/wasm", ".wasm")
import argparse
from http import server
parser = argparse.ArgumentParser(description='Start a local webserver with a Python terminal.')
parser.add_argument('--port', type=int, default=8000, help='port for the http server to listen on')
args = parser.parse_args()
class MyHTTPRequestHandler(server.SimpleHTTPRequestHandler):
def end_headers(self):
self.send_my_headers()
super().end_headers()
def send_my_headers(self):
self.send_header("Cross-Origin-Opener-Policy", "same-origin")
self.send_header("Cross-Origin-Embedder-Policy", "require-corp")
def run(server_class=server.HTTPServer, handler_class=MyHTTPRequestHandler):
"""Entrypoint for python server"""
server_address = ("0.0.0.0", args.port)
httpd = server_class(server_address, handler_class)
print("launching server...")
httpd.serve_forever()
# server.test(HandlerClass=MyHTTPRequestHandler, protocol="HTTP/1.1", port=args.port)
if __name__ == "__main__":
run()