forked from cvg/pixloc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
37 lines (30 loc) · 1015 Bytes
/
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
from pathlib import Path
import argparse
import http.server
PORT = 8000
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': 'text/javascript',
'.wasm': 'application/wasm',
'.json': 'application/json',
'.xml': 'application/xml',
}
parser = argparse.ArgumentParser()
parser.add_argument('--port', type=int, default=PORT,
help='Server local port.')
args = parser.parse_args()
port = args.port
httpd = http.server.HTTPServer(('localhost', port), HttpRequestHandler)
try:
relpath = Path(__file__).parent.resolve().relative_to(Path.cwd())
print(f'Open the viewer at http://localhost:{port}/{relpath}/viewer.html')
httpd.serve_forever()
except KeyboardInterrupt:
pass