-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
40 lines (30 loc) · 1.05 KB
/
server.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
import os
import tornado.ioloop
import tornado.web
import tornado.httpserver
from handlers.pages import IndexHandler
from handlers.query import QueryHandler
class Application(tornado.web.Application):
PORT = 8888
def __init__(self):
handlers = [
tornado.web.URLSpec(r'/', IndexHandler),
# API
tornado.web.URLSpec(r'/search', QueryHandler)
]
current_dir = os.path.dirname(__file__)
settings = dict(
template_path=os.path.join(current_dir, 'templates'),
static_path=os.path.join(current_dir, 'static'),
cookie_secret='947e5d1dc624bc99421bfc7e8ebad245'
)
super(Application, self).__init__(handlers, **settings)
def start(self):
"""Start the application."""
server = tornado.httpserver.HTTPServer(Application())
server.listen(Application.PORT)
tornado.ioloop.IOLoop.instance().start()
if __name__ == "__main__":
"""Start application upon running this file."""
app = Application()
app.start()