This repository has been archived by the owner on Jun 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetapp.py
94 lines (85 loc) · 3.13 KB
/
setapp.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# -*- coding: utf-8 -*-
import os
import cherrypy
from ws4py.server.cherrypyserver import WebSocketTool
import webservices
class SetApp:
@cherrypy.expose
def index(self, **kwargs):
return open('index.html')
if __name__ == '__main__':
import logging
import argparse
from ws4py import configure_logger
configure_logger(level=logging.DEBUG)
parser = argparse.ArgumentParser()
parser.add_argument('--env', help='set runtime environment')
args = parser.parse_args()
base_conf = {
'/': {
'tools.staticdir.root': os.path.abspath(os.getcwd()),
'tools.sessions.on': True,
'tools.trailing_slash.on': False
},
'/static': {
'tools.staticdir.on': True,
'tools.staticdir.dir': 'public'
},
}
cherrypy.config.update({
'server.socket_host': '0.0.0.0',
'server.socket_port': int(os.environ.get('PORT', 8080)),
'environment': args.env or 'staging'
})
webservices.MultiplayerWebSocketPlugin(cherrypy.engine).subscribe()
cherrypy.tools.websocket = WebSocketTool()
cherrypy.tree.mount(webservices.SolitaireWebService(), '/solitaire', {
'/' : {
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
'tools.sessions.on': True,
'tools.response_headers.on': True,
'tools.response_headers.headers': [('Content-Type', 'application/json')]
},
'/game': {
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
'tools.sessions.on': True,
'tools.response_headers.on': True,
'tools.response_headers.headers': [('Content-Type', 'application/json')]
}
})
cherrypy.tree.mount(webservices.MultiplayerWebService(), '/multiplayer', {
'/' : {
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
'tools.sessions.on': True,
'tools.response_headers.on': True,
'tools.response_headers.headers': [('Content-Type', 'application/json')],
},
'/go': {
'request.dispatch': cherrypy.dispatch.Dispatcher(),
'tools.sessions.on': True,
'tools.response_headers.on': True,
'tools.response_headers.headers': [('Content-Type', 'application/json')],
},
'/status': {
'request.dispatch': cherrypy.dispatch.Dispatcher(),
'tools.response_headers.on': True,
'tools.response_headers.headers': [('Content-Type', 'application/json')],
},
'/leave': {
'request.dispatch': cherrypy.dispatch.Dispatcher(),
},
'/destroy': {
'request.dispatch': cherrypy.dispatch.Dispatcher(),
},
'/find': {
'request.dispatch': cherrypy.dispatch.Dispatcher(),
},
'/ws': {
'request.dispatch': cherrypy.dispatch.Dispatcher(),
'tools.websocket.on': True,
'tools.websocket.handler_cls': webservices.MultiplayerWebSocket
},
})
cherrypy.quickstart(SetApp(), '/', base_conf)
cherrypy.engine.start()
cherrypy.engine.block()