-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebserver.py
48 lines (39 loc) · 1.48 KB
/
webserver.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
# --------------------------------------------------------------------- #
# External imports
# --------------------------------------------------------------------- #
import tornado.ioloop
import tornado.web
import tornado.httpserver
import sys
import os
# --------------------------------------------------------------------- #
# Local imports
# --------------------------------------------------------------------- #
from Backend.websocket_handler import BeagleWsHandler
# Root dir for web files
DIR_PATH = os.path.join( os.path.dirname(os.path.realpath(__file__)), "Frontend")
class IndexHandler(tornado.web.RequestHandler):
def get(self):
target_file = os.path.join(DIR_PATH, 'web', 'index.html')
self.render(target_file)
def make_app():
return tornado.web.Application([
(r"/websocket", BeagleWsHandler),
(r"/", IndexHandler),
(r"/(.*)", tornado.web.StaticFileHandler, {'path': DIR_PATH})
])
# --------------------------------------------------------------------- #
# Main
# --------------------------------------------------------------------- #
if __name__ == "__main__":
HOST = '10.20.0.10'
PORT = '8888'
# Get ip and port from cmd line args
if not len(sys.argv) < 3:
HOST = sys.argv[1]
PORT = sys.argv[2]
print('HOST: %s is listening on PORT: %s' % (HOST, PORT))
app = make_app()
tornado.httpserver.HTTPServer(app)
app.listen(PORT, HOST)
tornado.ioloop.IOLoop.current().start()