forked from the-benchmarker/web-frameworks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
executable file
·47 lines (30 loc) · 854 Bytes
/
server.py
File metadata and controls
executable file
·47 lines (30 loc) · 854 Bytes
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
#! /usr/bin/env python3
import cherrypy
IS_STANDALONE = __name__ == "__main__"
class WebRoot:
@cherrypy.expose
def index(self):
return ""
@cherrypy.expose
class UserAPI:
def GET(self, user_id):
return user_id
def POST(self):
return ""
WebRoot.user = UserAPI()
global_config = {
"environment": "production" if IS_STANDALONE else "embedded",
}
config = {
"/user": {"request.dispatch": cherrypy.dispatch.MethodDispatcher(), },
}
cherrypy.config.update(global_config)
if not IS_STANDALONE:
# on top of another WSGI server
# https://docs.cherrypy.org/en/latest/deploy.html#uwsgi
cherrypy.server.unsubscribe()
cherrypy.engine.start()
app = cherrypy.tree.mount(WebRoot(), "", config)
# standalone self-test
# python3 -m this_module_name
IS_STANDALONE and cherrypy.quickstart(app)