-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.py
41 lines (34 loc) · 1.25 KB
/
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
35
36
37
38
39
40
41
# -*- coding: utf-8 -*-
#test on python 3.4 ,python of lower version has different module organization.
import argparse
import http.server
from http.server import HTTPServer, BaseHTTPRequestHandler
import socketserver
import os
parser = argparse.ArgumentParser(description='Serve player webpage')
parser.add_argument('--host', help='address to serve on', type=str, default='127.0.0.1', action='store')
parser.add_argument('--port', help='port to serve on', type=int, default=8080, action='store')
parser.add_argument("path",nargs="?")
args = parser.parse_args()
Handler = http.server.SimpleHTTPRequestHandler
if args.path is None:
path = os.path.join(os.path.dirname(__file__), './build/')
else:
path = args.path
print("serving: " + path)
os.chdir(path)
Handler.extensions_map={
'.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',
'': 'application/octet-stream', # Default
}
socketserver.TCPServer.allow_reuse_address = True
httpd = socketserver.TCPServer((args.host, args.port), Handler)
print("serving at %s:%d" % (args.host, args.port))
httpd.serve_forever()