-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
52 lines (39 loc) · 1.26 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
import logging.config
from concurrent.futures import ThreadPoolExecutor
import tornado.web
import tornado.websocket
from tornado.ioloop import IOLoop
from tornado.options import options
from apps.urls import url_patterns
from contrib.db import AsyncConnection
from settings import settings
logging.config.dictConfig(settings.LOGGING)
# APPLICATION = {
# 'login_url': '/',
# 'xheaders': True,
# }
class Application(tornado.web.Application):
settings = {
'debug': settings.DEBUG,
'gzip': getattr(settings, 'GZIP', False),
'cookie_secret': settings.SECRET_KEY,
'xsrf_cookies': getattr(settings, 'XSRF_COOKIES', True),
'autoescape': "xhtml_escape",
'template_path': settings.TEMPLATE_ROOT,
'static_path': settings.STATIC_ROOT,
'static_url_prefix': settings.STATIC_URL,
}
def __init__(self):
super().__init__(url_patterns, **self.settings)
self.db = AsyncConnection(**settings.DATABASE)
self.executor = ThreadPoolExecutor()
def make_app(port):
app = Application()
app.listen(port)
return app
def main():
make_app(settings.PORT)
logging.info(f'server on http://127.0.0.1:{settings.PORT}')
IOLoop.current().start()
if __name__ == '__main__':
main()