-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
python-server.py
34 lines (30 loc) · 1.17 KB
/
python-server.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
# Based on:
# https://stackoverflow.com/a/21957017
# https://gist.github.com/HaiyangXu/ec88cbdce3cdbac7b8d5
# A simple python server to serve wasm files with the correct mime type
from http.server import SimpleHTTPRequestHandler
import socketserver
import sys
class Handler(SimpleHTTPRequestHandler):
extensions_map = {
'': 'application/octet-stream',
'.css': 'text/css',
'.html': 'text/html',
'.jpg': 'image/jpg',
'.js': 'application/x-javascript',
'.json': 'application/json',
'.manifest': 'text/cache-manifest',
'.png': 'image/png',
'.wasm': 'application/wasm',
'.xml': 'application/xml',
}
def end_headers(self):
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Cross-Origin-Embedder-Policy', 'require-corp')
self.send_header('Cross-Origin-Opener-Policy', 'same-origin')
SimpleHTTPRequestHandler.end_headers(self)
if __name__ == '__main__':
port = int(sys.argv[1]) if len(sys.argv) > 1 else 8000
with socketserver.TCPServer(("localhost", port), Handler) as httpd:
print("Serving on port", port)
httpd.serve_forever()