-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
60 lines (45 loc) · 1.72 KB
/
app.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
56
57
58
59
60
import os
import sentry_sdk
import tornado.ioloop
import tornado.options
import tornado.web
from pywebio.platform.tornado import webio_handler as ws_webio_handler
from pywebio.platform.tornado_http import webio_handler as http_webio_handler
from sentry_sdk.integrations.tornado import TornadoIntegration
from tornado.options import define, options
from src.handlers import feedback, index, privacy, terms
from src.settings import ALLOWED_ORIGINS, ENVIRONMENT, RECONNECT_TIMEOUT, SENTRY_DSN, STATIC
define('port', default=8080, help='Run on the given port', type=int)
define('debug', default=False, help='Run on the debug mode', type=bool)
sentry_sdk.init(
dsn=SENTRY_DSN,
environment=ENVIRONMENT,
integrations=[TornadoIntegration()],
)
class FourOhFourHandler(tornado.web.RequestHandler):
"""Page not found 404 handler"""
def get(self, slug: str) -> None:
del slug # Unused
self.render('src/templates/404.html')
def main() -> None:
"""Main entrypoint of the app"""
tornado.options.parse_command_line()
settings = dict(
site_title='Burplist',
debug=options.debug,
static_path=os.path.join(os.path.dirname(__file__), 'static'),
static_url_prefix=STATIC,
)
app = tornado.web.Application(
[
(r'/', ws_webio_handler(index, reconnect_timeout=RECONNECT_TIMEOUT, allowed_origins=ALLOWED_ORIGINS)),
(r'/terms', http_webio_handler(terms)),
(r'/privacy', http_webio_handler(privacy)),
(r'/feedback', http_webio_handler(feedback)),
(r'/([^/]+)', FourOhFourHandler),
], **settings
)
app.listen(options.port)
tornado.ioloop.IOLoop.current().start()
if __name__ == '__main__':
main()