-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtornado_server.py
37 lines (34 loc) · 1.08 KB
/
tornado_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
import argparse
import tornado.httpserver
from tornado import web
def parse_host_and_port():
parser = argparse.ArgumentParser()
parser.add_argument(
'--port',
action='store',
type=int,
dest='port',
default=5000,
help='The port that should be listned on.',
)
parser.add_argument(
'--host',
action='store',
type=str,
dest='host',
default='0.0.0.0',
help='The IP address on which to run the server.'
)
namespace = parser.parse_args()
return namespace.host, namespace.port
application = web.Application(
[
(r"/", web.StaticFileHandler, {'path': "./static/index.html"}),
(r"/(.*)", web.StaticFileHandler, {"path": "./static"}),
]
)
if __name__ == '__main__':
host, port = parse_host_and_port()
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(port, address=host)
tornado.ioloop.IOLoop.instance().start()