-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
49 lines (37 loc) · 1.24 KB
/
index.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
import Settings
import WebSocketHandler
import json
import cyclone.web
import sys
from twisted.internet import reactor
from twisted.python import log
class Application(cyclone.web.Application):
def __init__(self):
handlers = [
(r"/", cyclone.web.RedirectHandler, {"url": "http://www.liomka.io/demo"}),
(r'/ws', WebSocketHandler.WebSocketHandler),
(r'/api', ApiHandler),
(r'/favicon.ico', cyclone.web.StaticFileHandler, {'path': "./"}),
]
settings = {
"WSServerUrl": "ws://pywsserver.herokuapp.com/ws",
"template_path": Settings.TEMPLATE_PATH,
"static_path": Settings.STATIC_PATH,
}
cyclone.web.Application.__init__(self, handlers, **settings)
class ApiHandler(cyclone.web.RequestHandler):
@cyclone.web.asynchronous
def get(self, *args):
self.finish()
id = self.get_argument("id")
value = self.get_argument("value")
data = {"id": id, "value": value}
data = json.dumps(data)
@cyclone.web.asynchronous
def post(self):
pass
if __name__ == '__main__':
app = Application()
log.startLogging(sys.stdout)
reactor.listenTCP(Settings.HTTPPORT, app)
reactor.run()