forked from ZexinChen/AlphaTracker
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathserver.py
More file actions
27 lines (21 loc) · 832 Bytes
/
server.py
File metadata and controls
27 lines (21 loc) · 832 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 sys
import socketserver
import webbrowser
from http.server import SimpleHTTPRequestHandler
class Handler(SimpleHTTPRequestHandler):
def end_headers(self):
# Enable Cross-Origin Resource Sharing (CORS)
self.send_header("Access-Control-Allow-Origin", "*")
super().end_headers()
if sys.version_info < (3, 7, 5):
# Fix for WASM MIME type for older Python versions
Handler.extensions_map[".wasm"] = "application/wasm"
if __name__ == "__main__":
port = 8000
with socketserver.TCPServer(("", port), Handler, False) as httpd:
httpd.allow_reuse_address = True
httpd.server_bind()
httpd.server_activate()
print("Serving at: http://127.0.0.1:{}".format(port))
webbrowser.open_new("http://127.0.0.1:{}".format(port))
httpd.serve_forever()