forked from ishefi/semantle-he
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
67 lines (56 loc) · 1.58 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
61
62
63
64
65
66
67
#!/usr/bin/env python
import os
import tornado.httpserver
import tornado.ioloop
import tornado.web
from common import config
from common.logger import logger
import handlers
class WebApp(tornado.web.Application):
PATH = os.path.dirname(os.path.realpath(__file__))
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.api_key = config.api_key
static_handlers = [
(
r"/css/(.*)",
tornado.web.StaticFileHandler,
{"path": WebApp.PATH + "/static/css"},
),
(
r"/color/(.*)",
tornado.web.StaticFileHandler,
{"path": WebApp.PATH + "/static/color"},
),
(
r"/font-awesome/(.*)",
tornado.web.StaticFileHandler,
{"path": WebApp.PATH + "/static/font-awesome"},
),
(
r"/js/(.*)",
tornado.web.StaticFileHandler,
{"path": WebApp.PATH + "/static/js"},
),
(
r"/(favicon.ico|menu.html)",
tornado.web.StaticFileHandler,
{"path": WebApp.PATH + "/static/"},
),
]
if __name__ == "__main__":
handlers = handlers.get_handlers()
handlers.extend(static_handlers)
app = WebApp(handlers)
http_server = tornado.httpserver.HTTPServer(app)
port = int(os.environ["PORT"])
num_processes = int(os.environ.get("NUM_PROCESSES", 1))
http_server.bind(port)
http_server.start(num_processes)
while True:
logger.warning("Running app on port %d", port)
try:
tornado.ioloop.IOLoop.current().start()
except Exception as ex:
logger.exception(ex)
pass