-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.py
35 lines (29 loc) · 1.04 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
import os
import urllib
import tornado.ioloop
import tornado.httpserver
import tornado.options
import tornado.web
tornado.options.define('port', default=8888, help='port to listen on')
tornado.options.define('path', default='./', help='filesystem path')
class RenderMain(tornado.web.RequestHandler):
def get(self):
self.render("mock.html")
def main():
"""Start the tornado application."""
tornado.options.parse_command_line()
root = os.getenv('JUPYTERHUB_SERVICE_PREFIX', default='/')
url = os.getenv('JUPYTERHUB_SERVICE_URL', default=None)
if url is not None:
u = urllib.parse.urlparse(url)
tornado.options.options.port = u.port
app = tornado.web.Application([
(root, RenderMain),
(root + r'(.*\.(json|png|svg))', tornado.web.StaticFileHandler,
{'path': tornado.options.options.path}),
])
http_server = tornado.httpserver.HTTPServer(app)
http_server.listen(tornado.options.options.port)
tornado.ioloop.IOLoop.current().start()
if __name__ == "__main__":
main()