-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
56 lines (45 loc) · 1.97 KB
/
main.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
import asyncio
import os
import logging
from tornado.platform.asyncio import AsyncIOMainLoop
from tornado.web import Application, StaticFileHandler
from frontend.handler import editor, generic, project
from frontend.util.session import SessionManager
try:
import settings as Settings
except ImportError:
class Settings:
url_prefix = ""
port = 8888
def make_app():
current_dir = os.path.dirname(os.path.realpath(__file__))
fronted_dir = os.path.join(current_dir, "frontend")
static_dir = os.path.join(fronted_dir, "static")
settings = {
"app_root": current_dir,
"debug": True,
"compress_response": True,
"template_path": os.path.join(fronted_dir, "templates"),
"static_path": static_dir,
"cookie_secret": "__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__",
"static_url_prefix": Settings.url_prefix + r"/static/",
# "login_url": "/login"
}
sessions = SessionManager()
return Application((
(Settings.url_prefix + r"/main$", generic.MainHandler, {"sessions": sessions}, "main"),
(Settings.url_prefix + r"/help(?P<page>[a-z_]+)?$", generic.HelpHandler, {}, "help"),
(Settings.url_prefix + r"/editor$", editor.EditorHandler, {"sessions": sessions}, "editor"),
(Settings.url_prefix + r"/project/(?P<action>[a-z_]+)?$",
project.ProjectHandler, {"sessions": sessions}, "project"),
(Settings.url_prefix + r"/(?P<action>[a-z_]+)?$", generic.MainHandler, {"sessions": sessions}, "upload"),
(Settings.url_prefix + r"/(favicon\.ico)", StaticFileHandler),
(Settings.url_prefix + r"/(robots\.txt)", StaticFileHandler),
), **settings)
if __name__ == "__main__":
AsyncIOMainLoop().install()
app = make_app()
logging.basicConfig(level=logging.INFO)
logging.info("Starting server on port {}...".format(Settings.port))
app.listen(Settings.port, max_buffer_size=100 * 1024 * 1024)
asyncio.get_event_loop().run_forever()