-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.py
65 lines (51 loc) · 2.56 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
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
from tornado.ioloop import IOLoop
import tornado.web
from models import build_model
from dbmgr import DataMgr
from handler.gameStartHandler import GameStartHandler
from handler.predictNewShubNoHandler import PredictNewShubNoHandler
from handler.logElapsedTimes import LogElapsedTimesHandler
from handler.logQuestionnaire import LogQuestionnaireHandler
from handler.logRandomFeedback import LogRandomFeedbackHandler, LogUserPaymentHandler
from handler.logAttention import LogAttentionHandler
from handler.logUserPerformanceHandler import LogUserPerformanceHandler
port = 8888
class WebServer(tornado.web.Application):
def __init__(self):
self.datamgr = DataMgr()
self.model = build_model()
handlers = [
(r'/', tornado.web.RedirectHandler, dict(url=r"/index.htm")),
(r'/(index\.htm)', tornado.web.StaticFileHandler, {'path': '../FrontEnd'}),
(r'/js/(.*)', tornado.web.StaticFileHandler, {'path': '../FrontEnd/js'}),
(r'/(favicon\.ico)', tornado.web.StaticFileHandler, {'path': '../FrontEnd/static'}),
(r'/static/(.*)', tornado.web.StaticFileHandler, {'path': '../FrontEnd/static'}),
(r'/api/gameStart', GameStartHandler, dict(datamgr=self.datamgr)),
(r'/api/predictNewShubNo', PredictNewShubNoHandler, dict(model=self.model, datamgr=self.datamgr)),
(r'/api/log/questionnaireAnswer', LogQuestionnaireHandler, dict(datamgr=self.datamgr)),
(r'/api/log/elapsedTime', LogElapsedTimesHandler, dict(datamgr=self.datamgr)),
(r'/api/log/randomFeedback', LogRandomFeedbackHandler, dict(datamgr=self.datamgr)),
(r'/api/log/userPerformance', LogUserPerformanceHandler, dict(datamgr=self.datamgr)),
(r'/api/log/userPayment', LogUserPaymentHandler, dict(datamgr=self.datamgr)),
(r'/api/log/attention', LogAttentionHandler, dict(datamgr=self.datamgr))
]
tornado.web.Application.__init__(self, handlers)
def runServer():
WebServer().listen(port)
IOLoop.instance().start()
def runSslServer(certfile, keyfile):
tornado.httpserver.HTTPServer(WebServer(), ssl_options={
"certfile": certfile,
"keyfile": keyfile,
}).listen(port)
tornado.ioloop.IOLoop.instance().start()
if __name__ == "__main__":
if len(sys.argv) == 3:
certfile = sys.argv[1] # /etc/ssl/certs/fullchain14.pem
keyfile = sys.argv[2] # /home/itsmladm/AlienZoo/alienzoo/privkey14.pem
runSslServer(certfile, keyfile)
else:
runServer()