-
Notifications
You must be signed in to change notification settings - Fork 2
/
start.py
executable file
·55 lines (40 loc) · 1.26 KB
/
start.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
import argparse
import webbrowser
import time
import sys
import os
from flask import Flask
from threading import Thread
from flask import send_from_directory
root = os.path.dirname(os.path.abspath(__file__))
app = Flask(__name__, static_folder=root)
@app.route('/<path:path>', methods=['GET'])
def static_proxy(path):
return send_from_directory(root, path)
@app.route('/', methods=['GET'])
def index():
return send_from_directory(root, 'index.html')
def start_webserver(port):
app.run(host='0.0.0.0', port=port, debug=True,
threaded=True, use_reloader=False)
if __name__ == '__main__':
port = 8000
ap = argparse.ArgumentParser()
ap.add_argument("-p", "--port", required=False,
help="port (8000 is default")
args = vars(ap.parse_args())
if "port" in args and args['port'] is not None:
port = int(args['port'])
print("Starting webserver on port: {}".format(port))
t = Thread(target=start_webserver, args=(port,))
t.daemon = True
t.start()
time.sleep(1.0)
webbrowser.open('http://localhost:{}'.format(port))
while True:
try:
time.sleep(0.1)
except KeyboardInterrupt:
print("Exiting...")
sys.exit(0)