-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
108 lines (91 loc) · 3.29 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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
__author__ = 'Jon'
from peopleapi import PeopleApi
from adminapi import AdminApi
from reportapi import ReportApi
from schoolapi import SchoolApi
from dbtools import DBTools as DB
import os
import cherrypy
import sys
class App(object):
def index(self):
host = cherrypy.request.headers['Host']
#realhost = cherrypy.request.headers['X-Forwarded-Host']
realhost = 'blah'
return 'Hello! I am ' + realhost + ' though I look like ' + host
index.exposed = True
if __name__ == '__main__':
argc = len(sys.argv)
db = DB()
if argc == 1:
db.initDB(None)
else:
db.initDB(sys.argv[1])
app = App()
app.people = PeopleApi(db)
app.people.exposed = True
app.report = ReportApi(db)
app.report.exposed = True
app.school = SchoolApi(db)
app.school.exposed = True
app.admin = AdminApi(db)
app.admin.exposed = True
app.admin.people = PeopleApi(db,True)
app.admin.report = ReportApi(db,True)
app.admin.school = SchoolApi(db,True)
app.admin.people.exposed = True
app.admin.report.exposed = True
app.admin.school.exposed = True
conf = {
'/' : {
'tools.sessions.on' : True,
'tools.staticdir.root' : os.path.abspath(os.getcwd())
},
'/admin' : {
'tools.sessions.on' : True,
'tools.staticdir.root' : os.path.abspath(os.getcwd())
},
'/people' : {
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
'tools.json_in.on': True,
'tools.json_out.on' : True,
},
'/report' : {
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
'tools.response_headers.on': True,
'tools.json_in.on': True,
'tools.json_out.on' : True,
'tools.response_headers.headers': [('Content-Type', 'application/json')]
},
'/school' : {
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
'tools.response_headers.on': True,
'tools.json_in.on': True,
'tools.json_out.on' : True,
'tools.response_headers.headers': [('Content-Type', 'application/json')]
},
'/admin/people' : {
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
'tools.response_headers.on': True,
'tools.json_in.on': True,
'tools.json_out.on' : True,
'tools.response_headers.headers': [('Content-Type', 'application/json')]
},
'/admin/report' : {
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
'tools.response_headers.on': True,
'tools.json_in.on': True,
'tools.json_out.on' : True,
'tools.response_headers.headers': [('Content-Type', 'text/plain')]
},
'/admin/school' : {
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
'tools.response_headers.on': True,
'tools.json_in.on': True,
'tools.json_out.on' : True,
'tools.response_headers.headers': [('Content-Type', 'text/plain')]
}
}
# FIXME check what Content-Type should be for response headers when using JSON
cherrypy.config.update({'server.socket_port' : 8081})
cherrypy.quickstart(app,'/',conf)