-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
45 lines (39 loc) · 1.28 KB
/
main.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
import cherrypy
from api import Api
from api.helpers import cors
# ;)
import antigravity # noqa: F401
# ok I'm sorry
# This responds to our requests for the homepage, playground, etc.
class Root:
@cherrypy.expose
def index(self):
return open('homepage/index.html', 'r').read()
@cherrypy.expose
def playground(self):
return open('homepage/playground.html', 'r').read()
# If this is the main file, then we intialize CherryPy.
if __name__ == '__main__':
# For REST endpoints, we use this REST configuration to
# allow us to respond to HTTP methods like POST and support CORS.
REST_conf = {
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
'tools.sessions.on': True,
'tools.response_headers.on': True,
'tools.response_headers.headers': [
('Content-Type', 'application/json')
],
'cors.expose_public.on': True
}
# We mount the main page separately from the API.
app = cherrypy.tree.mount(Api(), '/api', {
'/guild': REST_conf,
'/channel': REST_conf,
'/dm': REST_conf,
'/users': REST_conf
})
app.toolboxes['cors'] = cors
# Set up root endpoint.
cherrypy.quickstart(Root(), '/', {
'/favicon.ico': {'tools.staticfile.on': False}
})