forked from dipdowel/graph1_wasm_demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph1_demo_serve.py
More file actions
51 lines (44 loc) · 1.48 KB
/
graph1_demo_serve.py
File metadata and controls
51 lines (44 loc) · 1.48 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
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
import http.server
import socketserver
import os
FILES_LOCATION='./pkg'
PORT = 8080
web_dir = os.path.join(os.path.dirname(__file__), FILES_LOCATION)
os.chdir(web_dir)
class HttpRequestHandler(http.server.SimpleHTTPRequestHandler):
extensions_map = {
'': 'application/octet-stream',
'.manifest': 'text/cache-manifest',
'.html': 'text/html',
'.png': 'image/png',
'.jpg': 'image/jpg',
'.svg': 'image/svg+xml',
'.css': 'text/css',
'.js': 'application/x-javascript',
'.wasm': 'application/wasm',
'.json': 'application/json',
'.xml': 'application/xml',
}
def end_headers(self):
"""
Overrides the SimpleHTTPRequestHandler to
send extra headers.
"""
self.send_safe_context_headers()
super().end_headers()
def send_safe_context_headers(self):
"""
Allows SharedArrayBuffer to work from our demo server.
"""
self.send_header("Cross-Origin-Opener-Policy", "same-origin")
self.send_header("Cross-Origin-Embedder-Policy", "require-corp")
socketserver.TCPServer.allow_reuse_address = True
with socketserver.TCPServer(("localhost", PORT), HttpRequestHandler) as httpd:
try:
print(f"serving {str(web_dir)} at http://localhost:{PORT}")
httpd.serve_forever()
except KeyboardInterrupt:
print("[!] Keyboard Interrupted!")
httpd.server_close()
httpd.shutdown()