-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathindex.py
More file actions
53 lines (41 loc) · 1.56 KB
/
index.py
File metadata and controls
53 lines (41 loc) · 1.56 KB
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
""" SmartAPI Entry Point """
import logging
from os.path import exists
from threading import Thread
from aiocron import crontab
from biothings.web.launcher import main
from tornado.ioloop import IOLoop
from tornado.web import RequestHandler
from tornado.options import define, options
from admin import routine
from utils.indices import setup
define("prod", default=False, help="Run in production mode", type=bool)
def run_routine():
thread = Thread(target=routine, daemon=True)
thread.start()
class WebAppHandler(RequestHandler):
def get(self):
if exists("../web-app/dist/index.html"):
self.render("../web-app/dist/index.html")
if __name__ == "__main__":
logger = logging.getLogger("routine")
options.parse_command_line()
if not options.debug and options.prod:
crontab("0 0 * * *", func=run_routine, start=True)
logger.info("Crontab configured successfully.")
IOLoop.current().add_callback(setup)
main(
[
(r"/user/?", "handlers.api.UserInfoHandler"),
(r"/login/?", "handlers.api.LoginHandler"),
(r"/oauth", "handlers.oauth.GitHubLoginHandler"),
(r"/logout/?", "handlers.api.LogoutHandler"),
(r"/sitemap.xml()", "tornado.web.StaticFileHandler", {"path": "../web-app/dist/sitemap.xml"}),
(r"/((?:img|assets)/.*)", "tornado.web.StaticFileHandler", {"path": "../web-app/dist/"}),
],
{
"default_handler_class": WebAppHandler,
"static_path": "../web-app/dist/",
},
use_curl=True,
)