aboutsummaryrefslogtreecommitdiffstats
path: root/fg21sim/webui/app.py
blob: 8199aa7e42c116f7fa71eacac09d01b009afa625 (plain)
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
# Copyright (c) 2016 Weitian LI <liweitianux@live.com>
# MIT license

"""
Web user interface (UI) of "fg21sim" based upon Tornado_ web server and
using the WebSocket_ protocol.

.. _Tornado: http://www.tornadoweb.org/

.. _WebSocket: https://en.wikipedia.org/wiki/WebSocket ,
   http://caniuse.com/#feat=websockets
"""

import os

import tornado.web

from .websocket import FG21simWSHandler


class IndexHandler(tornado.web.RequestHandler):
    def get(self):
        self.render("index.html")


_settings = {
    # The static files will be served from the default "/static/" URI.
    # Recommend to use `{{ static_url(filepath) }}` in the templates.
    "static_path": os.path.join(os.path.dirname(__file__), "static"),
    "template_path": os.path.join(os.path.dirname(__file__), "templates"),
}


# FIXME:
# * Subclass on `tornado.web.Application`
# * hold the attributes (e.g., configs, console) ??
def make_application(**kwargs):
    settings = _settings
    settings.update(kwargs)
    appplication = tornado.web.Application(
        handlers=[
            (r"/", IndexHandler),
            (r"/ws", FG21simWSHandler),
        ], **settings)
    return appplication